{"record":{"id":"e636d7c771a9eeec","repo":"AlistGo/alist","slug":"gofile-api-error-s-code-s","errorCode":null,"errorMessage":"gofile API error: %s (code: %s)","messagePattern":"gofile API error: (.+?) \\(code: (.+?)\\)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/gofile/util.go","lineNumber":146,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn d.handleError(resp)\n\t}\n\n\treturn nil\n}\n\nfunc (d *Gofile) handleError(resp *http.Response) error {\n\tbody, _ := io.ReadAll(resp.Body)\n\tlog.Debugf(\"Gofile API error (HTTP %d): %s\", resp.StatusCode, string(body))\n\n\tvar errorResp ErrorResponse\n\tif err := json.Unmarshal(body, &errorResp); err == nil && errorResp.Status == \"error\" {\n\t\treturn fmt.Errorf(\"gofile API error: %s (code: %s)\", errorResp.Error.Message, errorResp.Error.Code)\n\t}\n\n\treturn fmt.Errorf(\"gofile API error: HTTP %d - %s\", resp.StatusCode, string(body))\n}\n\nfunc (d *Gofile) uploadFile(ctx context.Context, folderId string, file model.FileStreamer, up driver.UpdateProgress) (*UploadResponse, error) {\n\tvar body bytes.Buffer\n\twriter := multipart.NewWriter(&body)\n\n\tif folderId != \"\" {\n\t\twriter.WriteField(\"folderId\", folderId)\n\t}\n\n\tpart, err := writer.CreateFormFile(\"file\", filepath.Base(file.GetName()))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/gofile/util.go#L128-L164","documentation":"Central Gofile API error formatter: when a response body parses as JSON with status==\"error\", the driver returns 'gofile API error: <message> (code: <code>)'. It carries Gofile's own error message and machine-readable code for any API call routed through handleError.","triggerScenarios":"Any Gofile API operation (account, folder create, upload server, contents, delete) whose response JSON has status 'error' — e.g. invalid token ('unauthorized'), nonexistent folder, quota, or permission errors.","commonSituations":"Expired/invalid API token across all operations; uploading into a folder ID that was deleted; content- or account-level limits; passing wrong parameter types to folder endpoints.","solutions":["Map the parenthesized code: unauthorized/invalid token -> refresh token in driver config; not-found -> verify folder/file IDs; rate-limit -> back off","Verify the token and account state in the Gofile dashboard","Retry idempotent operations after resolving the specific code","Check driver logs — handleError also logs the raw HTTP status and body at debug level"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isGofileAPIError(err error) bool {\n  return err != nil && strings.HasPrefix(err.Error(), \"gofile API error:\") && strings.Contains(err.Error(), \"(code:\")\n}","tryCatchPattern":"err := op.Do()\nif err != nil {\n  var msg = err.Error()\n  switch {\n  case strings.Contains(msg, \"(code: unauthorized\") || strings.Contains(msg, \"(code: invalid\"):\n    // token problem: stop and reconfigure\n  case strings.Contains(msg, \"(code: rate\"):\n    // backoff and retry\n  default:\n    return err\n  }\n}","preventionTips":["Centralize handling of '(code: ...)' values instead of string-matching messages","Refresh tokens proactively before expiry"],"tags":["gofile","api","http","error-response"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}