AlistGo/alist · error
gofile API error: %s (code: %s)
Error message
gofile API error: %s (code: %s)
What it means
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.
Source
Thrown at drivers/gofile/util.go:146
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return d.handleError(resp)
}
return nil
}
func (d *Gofile) handleError(resp *http.Response) error {
body, _ := io.ReadAll(resp.Body)
log.Debugf("Gofile API error (HTTP %d): %s", resp.StatusCode, string(body))
var errorResp ErrorResponse
if err := json.Unmarshal(body, &errorResp); err == nil && errorResp.Status == "error" {
return fmt.Errorf("gofile API error: %s (code: %s)", errorResp.Error.Message, errorResp.Error.Code)
}
return fmt.Errorf("gofile API error: HTTP %d - %s", resp.StatusCode, string(body))
}
func (d *Gofile) uploadFile(ctx context.Context, folderId string, file model.FileStreamer, up driver.UpdateProgress) (*UploadResponse, error) {
var body bytes.Buffer
writer := multipart.NewWriter(&body)
if folderId != "" {
writer.WriteField("folderId", folderId)
}
part, err := writer.CreateFormFile("file", filepath.Base(file.GetName()))
if err != nil {
return nil, err
}
View on GitHub (pinned to 843d9dc814)
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
Defensive patterns
Strategy: try-catch
Type guard
func isGofileAPIError(err error) bool {
return err != nil && strings.HasPrefix(err.Error(), "gofile API error:") && strings.Contains(err.Error(), "(code:")
} Try / catch
err := op.Do()
if err != nil {
var msg = err.Error()
switch {
case strings.Contains(msg, "(code: unauthorized") || strings.Contains(msg, "(code: invalid"):
// token problem: stop and reconfigure
case strings.Contains(msg, "(code: rate"):
// backoff and retry
default:
return err
}
} Prevention
- Centralize handling of '(code: ...)' values instead of string-matching messages
- Refresh tokens proactively before expiry
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- gofile API error: HTTP %d - %s
- rename API call failed: %w
- http request [%s] failure,status: %d response:%s
- invalid label ID '%s': %v
- missing cookie or qrcode account
AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15).
Data as JSON: /api/errors/e636d7c771a9eeec.
Report an issue: GitHub.