{"record":{"id":"88287ba761947745","repo":"plandex-ai/plandex","slug":"failed-to-fetch-custom-model","errorCode":null,"errorMessage":"Failed to fetch custom model: ","messagePattern":"Failed to fetch custom model: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/models.go","lineNumber":354,"sourceCode":"\tw.WriteHeader(http.StatusOK)\n\n\tlog.Println(\"Successfully imported custom models/providers/model packs\")\n}\n\nfunc GetCustomModelHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for GetCustomModelHandler\")\n\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\tid := mux.Vars(r)[\"modelId\"]\n\n\tres, err := db.GetCustomModel(auth.OrgId, id)\n\tif err != nil {\n\t\tlog.Printf(\"Error fetching custom model: %v\\n\", err)\n\t\thttp.Error(w, \"Failed to fetch custom model: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tif res == nil {\n\t\thttp.Error(w, \"Custom model not found\", http.StatusNotFound)\n\t\treturn\n\t}\n\n\terr = json.NewEncoder(w).Encode(res.ToApi())\n\tif err != nil {\n\t\tlog.Printf(\"Error encoding custom model: %v\\n\", err)\n\t\thttp.Error(w, fmt.Sprintf(\"Error encoding custom model: %v\", err), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tlog.Println(\"Successfully fetched custom model\")\n}\n","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/models.go#L336-L372","documentation":"GetCustomModelHandler returns this 500 when db.GetCustomModel(auth.OrgId, modelId) returns an error while fetching a single custom model by id for the authenticated org. This is a database-level failure (not 'not found' — that returns 409/404 separately via res == nil).","triggerScenarios":"GET the custom model endpoint with a modelId path variable when the underlying query errors: DB unreachable, connection pool exhausted, request context canceled, or schema mismatch (missing table/column from an unmigrated database).","commonSituations":"Postgres outage or restart during a request; misconfigured DB credentials on self-hosted; server upgraded without migrations; network partition between server and database.","solutions":["Check the server log 'Error fetching custom model: ...' for the underlying DB error","Verify database connectivity and credentials","Run pending migrations so the custom models schema matches the server version","Retry the request if the failure was transient"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// 500 on fetch — check underlying DB error, retry transient failures\nif resp.StatusCode == 500 && strings.Contains(bodyText, \"Failed to fetch custom model\") {\n    return backoffRetry(func() error { return fetchModel(id) }, 3)\n}","preventionTips":["Keep the DB connection healthy and migrations applied","Use long-enough client timeouts to avoid context cancellation","Alert on 500 rates from the custom model endpoints","Verify DB credentials after any infra changes"],"tags":["database","http-500","fetch"],"backgroundTag":"database-query-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}