MCPcopy
hub / github.com/mudler/LocalAI / authError

Function authError

core/http/auth/middleware.go:603–628  ·  view source on GitHub ↗

authError returns an appropriate error response.

(c echo.Context, appConfig *config.ApplicationConfig)

Source from the content-addressed store, hash-verified

601
602// authError returns an appropriate error response.
603func authError(c echo.Context, appConfig *config.ApplicationConfig) error {
604 c.Response().Header().Set("WWW-Authenticate", "Bearer")
605
606 if appConfig.OpaqueErrors {
607 return c.NoContent(http.StatusUnauthorized)
608 }
609
610 contentType := c.Request().Header.Get("Content-Type")
611 if strings.Contains(contentType, "application/json") {
612 return c.JSON(http.StatusUnauthorized, schema.ErrorResponse{
613 Error: &schema.APIError{
614 Message: "An authentication key is required",
615 Code: http.StatusUnauthorized,
616 Type: "invalid_request_error",
617 },
618 })
619 }
620
621 return c.JSON(http.StatusUnauthorized, schema.ErrorResponse{
622 Error: &schema.APIError{
623 Message: "An authentication key is required",
624 Code: http.StatusUnauthorized,
625 Type: "invalid_request_error",
626 },
627 })
628}

Callers 1

MiddlewareFunction · 0.85

Calls 6

HeaderMethod · 0.80
ContainsMethod · 0.80
JSONMethod · 0.80
SetMethod · 0.65
GetMethod · 0.65
RequestMethod · 0.65

Tested by

no test coverage detected