MCPcopy Index your code
hub / github.com/coder/coder / writeAIProviderError

Function writeAIProviderError

coderd/ai_providers.go:540–561  ·  view source on GitHub ↗

writeAIProviderError translates an error from the AI provider lookup/update/delete paths into the right HTTP status code. logMsg labels the log line for operator debugging, and userMsg is the internal-error response message shown to the API consumer when no more specific branch fires.

(ctx context.Context, logger slog.Logger, rw http.ResponseWriter, err error, logMsg, userMsg string)

Source from the content-addressed store, hash-verified

538// internal-error response message shown to the API consumer when no
539// more specific branch fires.
540func writeAIProviderError(ctx context.Context, logger slog.Logger, rw http.ResponseWriter, err error, logMsg, userMsg string) {
541 if errors.Is(err, errAIProviderInvalidName) {
542 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
543 Message: fmt.Sprintf("Invalid provider id or name: must be a UUID or match %s.", codersdk.AIProviderNameRegex),
544 })
545 return
546 }
547 if errors.Is(err, sql.ErrNoRows) {
548 httpapi.ResourceNotFound(rw)
549 return
550 }
551 if dbauthz.IsNotAuthorizedError(err) {
552 logger.Error(ctx, logMsg, slog.Error(err))
553 httpapi.Forbidden(rw)
554 return
555 }
556 logger.Error(ctx, logMsg, slog.Error(err))
557 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
558 Message: userMsg,
559 Detail: err.Error(),
560 })
561}
562
563// loadAIProviderKeysByProvider fetches keys for every live provider in
564// one query and buckets the rows by ProviderID, so the list handler

Callers 3

aiProvidersGetMethod · 0.85
aiProvidersUpdateMethod · 0.85
aiProvidersDeleteMethod · 0.85

Calls 6

WriteFunction · 0.92
ResourceNotFoundFunction · 0.92
IsNotAuthorizedErrorFunction · 0.92
ForbiddenFunction · 0.92
IsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected