authError returns an appropriate error response.
(c echo.Context, appConfig *config.ApplicationConfig)
| 601 | |
| 602 | // authError returns an appropriate error response. |
| 603 | func 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 | } |