plandex-ai/plandex · error

Failed to fetch custom model:

Error message

Failed to fetch custom model: 

What it means

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).

Source

Thrown at app/server/handlers/models.go:354

	w.WriteHeader(http.StatusOK)

	log.Println("Successfully imported custom models/providers/model packs")
}

func GetCustomModelHandler(w http.ResponseWriter, r *http.Request) {
	log.Println("Received request for GetCustomModelHandler")

	auth := Authenticate(w, r, true)
	if auth == nil {
		return
	}

	id := mux.Vars(r)["modelId"]

	res, err := db.GetCustomModel(auth.OrgId, id)
	if err != nil {
		log.Printf("Error fetching custom model: %v\n", err)
		http.Error(w, "Failed to fetch custom model: "+err.Error(), http.StatusInternalServerError)
		return
	}

	if res == nil {
		http.Error(w, "Custom model not found", http.StatusNotFound)
		return
	}

	err = json.NewEncoder(w).Encode(res.ToApi())
	if err != nil {
		log.Printf("Error encoding custom model: %v\n", err)
		http.Error(w, fmt.Sprintf("Error encoding custom model: %v", err), http.StatusInternalServerError)
		return
	}

	log.Println("Successfully fetched custom model")
}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the server log 'Error fetching custom model: ...' for the underlying DB error
  2. Verify database connectivity and credentials
  3. Run pending migrations so the custom models schema matches the server version
  4. Retry the request if the failure was transient
Defensive patterns

Strategy: retry

Try / catch

// 500 on fetch — check underlying DB error, retry transient failures
if resp.StatusCode == 500 && strings.Contains(bodyText, "Failed to fetch custom model") {
    return backoffRetry(func() error { return fetchModel(id) }, 3)
}

Prevention

When it happens

Trigger: 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).

Common situations: Postgres outage or restart during a request; misconfigured DB credentials on self-hosted; server upgraded without migrations; network partition between server and database.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/88287ba761947745. Report an issue: GitHub.