{"record":{"id":"7571e34b1bbfc373","repo":"charmbracelet/crush","slug":"failed-to-get-session-history-files-status-code","errorCode":null,"errorMessage":"failed to get session history files: status code %d","messagePattern":"failed to get session history files: status code (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":632,"sourceCode":"\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to get session: status code %d\", rsp.StatusCode)\n\t}\n\tvar sess proto.Session\n\tif err := json.NewDecoder(rsp.Body).Decode(&sess); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode session: %w\", err)\n\t}\n\treturn &sess, nil\n}\n\n// ListSessionHistoryFiles retrieves history files for a session as proto types.\nfunc (c *Client) ListSessionHistoryFiles(ctx context.Context, id string, sessionID string) ([]proto.File, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/sessions/%s/history\", id, sessionID), nil, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get session history files: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to get session history files: status code %d\", rsp.StatusCode)\n\t}\n\tvar files []proto.File\n\tif err := json.NewDecoder(rsp.Body).Decode(&files); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode session history files: %w\", err)\n\t}\n\treturn files, nil\n}\n\n// CreateSession creates a new session in a workspace as a proto type.\nfunc (c *Client) CreateSession(ctx context.Context, id string, title string) (*proto.Session, error) {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/sessions\", id), nil, jsonBody(proto.Session{Title: title}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create session: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to create session: status code %d\", rsp.StatusCode)\n\t}","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L614-L650","documentation":"ListSessionHistoryFiles reached the history endpoint but the server responded with a non-200 status code. The client returns this error with the status code embedded. The body is not parsed, so the actual server-side error detail is discarded unless you inspect the exchange manually.","triggerScenarios":"GET /workspaces/{id}/sessions/{sessionID}/history returns 404 (workspace or session not found), 401/403 (bad credentials/permissions), 500 (server error), etc.","commonSituations":"Deleted or mistyped session ID; expired API credentials; missing permission on the workspace; server-side failure while reading history files.","solutions":["Check the status code in the error message and handle it (404: verify workspace/session IDs exist; 401/403: refresh credentials; 5xx: retry later).","Verify the session belongs to the given workspace ID.","Refresh or re-issue authentication credentials.","Capture the response body for diagnostics (may require a modified client or proxy).","Retry with backoff for 429/5xx responses."],"exampleFix":"// before\nfiles, err := client.ListSessionHistoryFiles(ctx, wsID, sessID)\nif err != nil { return err }\n// after\nfiles, err := client.ListSessionHistoryFiles(ctx, wsID, sessID)\nif err != nil {\n    if strings.Contains(err.Error(), \"status code 404\") {\n        return fmt.Errorf(\"session %q not found in workspace %q\", sessID, wsID)\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// Confirm the session exists first\n_, err := client.GetSession(ctx, wsID, sessID)\nif err != nil {\n    return fmt.Errorf(\"session %s not accessible in workspace %s: %w\", sessID, wsID, err)\n}","typeGuard":"func isStatusCodeError(err error, code int) bool {\n    return err != nil && strings.Contains(err.Error(), fmt.Sprintf(\"status code %d\", code))\n}","tryCatchPattern":"files, err := client.ListSessionHistoryFiles(ctx, wsID, sessID)\nif err != nil {\n    switch {\n    case isStatusCodeError(err, 404):\n        return fmt.Errorf(\"session %q not found\", sessID)\n    case isStatusCodeError(err, 401), isStatusCodeError(err, 403):\n        return fmt.Errorf(\"refresh credentials: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate workspace/session IDs before calling.","Refresh auth tokens before expiry.","Check workspace permissions.","Retry only 429/5xx statuses."],"tags":["http","status-code","client"],"backgroundTag":"http-non-200-response","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}