{"record":{"id":"dbb49b19c2501c0f","repo":"IceWhaleTech/CasaOS","slug":"e-error-message","errorCode":null,"errorMessage":"e.Error.Message","messagePattern":"e\\.Error\\.Message","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/onedrive/util.go","lineNumber":144,"sourceCode":"\t}\n\tif resp != nil {\n\t\treq.SetResult(resp)\n\t}\n\tvar e RespErr\n\treq.SetError(&e)\n\tres, err := req.Execute(method, url)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif e.Error.Code != \"\" {\n\t\tif e.Error.Code == \"InvalidAuthenticationToken\" {\n\t\t\terr = d.refreshToken()\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\treturn d.Request(url, method, callback, resp)\n\t\t}\n\t\treturn nil, errors.New(e.Error.Message)\n\t}\n\treturn res.Body(), nil\n}\n\nfunc GetConfig() Onedrive {\n\tconfig := Onedrive{}\n\tconfig.ClientID = client_id\n\tconfig.ClientSecret = client_secret\n\tconfig.RootFolderID = \"/\"\n\tconfig.AuthUrl = \"https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=\" + client_id + \"&response_type=code&redirect_uri=https%3A%2F%2Fcloudoauth.files.casaos.app&scope=offline_access+files.readwrite.all&state=${HOST}%2Fv1%2Frecover%2FOnedrive\"\n\tconfig.Icon = \"./img/driver/OneDrive.svg\"\n\tconfig.Region = \"global\"\n\tconfig.RedirectUri = \"https://cloudoauth.files.casaos.app\"\n\n\treturn config\n}\n","sourceCodeStart":126,"sourceCodeEnd":161,"githubUrl":"https://github.com/IceWhaleTech/CasaOS/blob/0d3b2f444ec0193193cf03eef6d43c6e35b0183e/drivers/onedrive/util.go#L126-L161","documentation":"The OneDrive API returned an error payload (the TokenErr struct's Error field was non-empty) during an authenticated request, and the driver surfaces the endpoint's Message field verbatim. Adjacent logic auto-recovers InvalidAuthenticationToken by refreshing the access token and retrying once; any other error code is fatal with this message.","triggerScenarios":"Any Request() call (list, upload, download, create folder) that returns an error body with e.Error.Code set — e.g. 'itemNotFound', 'accessDenied', 'quotaLimitReached', 'nameAlreadyExists' — while the Bearer token is still valid.","commonSituations":"The target path/item no longer exists (deleted or moved); the granted scope lacks permission for the operation; OneDrive personal vs business region mismatch; throttling (activityLimitReached) under heavy use.","solutions":["Match the text in the error message to the OneDrive error code table (itemNotFound, accessDenied, etc.) — the Code determines the real fix, but only the Message is surfaced, so log the body too.","For itemNotFound: refresh the parent listing — the item was moved or deleted by another client.","For accessDenied/scope errors: re-authorize with Files.ReadWrite.All and confirm the right account/region.","For throttling: back off and retry; Microsoft returns Retry-After headers."],"exampleFix":"// before\nreturn nil, errors.New(e.Error.Message)\n\n// after (surface the code for diagnosability)\nreturn nil, fmt.Errorf(\"onedrive: %s: %s\", e.Error.Code, e.Error.Message)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"body, err := d.Request(url, method, cb, resp)\nif err != nil {\n\t// invalid_grant-style token failures are re-thrown after the built-in refresh retry;\n\t// distinguish retryable (throttling) from permanent (notFound/accessDenied) via message\n\tif strings.Contains(err.Error(), \"activityLimitReached\") {\n\t\ttime.Sleep(30 * time.Second) // honor Retry-After\n\t\treturn d.Request(url, method, cb, resp)\n\t}\n\treturn err\n}","preventionTips":["Wrap Request and include e.Error.Code in errors so callers can branch on codes not messages","Refresh directory listings after external deletions before acting on cached IDs","Rate-limit listing calls to avoid OneDrive throttling"],"tags":["onedrive","api-error","http","driver"],"backgroundTag":null,"analyzedSha":"0d3b2f444ec0193193cf03eef6d43c6e35b0183e","analyzedAt":"2026-08-15T13:27:57.821Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}