AuthErrorHandler

works.iterative.server.http.AuthErrorHandler

Error handler for authentication and authorization failures.

This object provides HTTP4S response mapping for AuthenticationError enum variants. It ensures consistent error responses across the application:

  • Unauthenticated → 401 Unauthorized
  • Forbidden → 403 Forbidden
  • InvalidCredentials → 401 Unauthorized
  • TokenExpired → 401 Unauthorized
  • InvalidToken → 401 Unauthorized

Usage in HTTP routes:

 service.updateDocument(id, title)
   .mapError {
     case e: AuthenticationError => AuthErrorHandler.toResponse(e)
   }

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def toResponse(error: AuthenticationError): Response[IO]

Convert AuthenticationError to HTTP Response.

Convert AuthenticationError to HTTP Response.

This method pattern matches on the AuthenticationError enum to determine the appropriate HTTP status code and response body. It also logs authentication failures for security monitoring and debugging.

Value parameters

error

The authentication error

Attributes

Returns

HTTP Response with appropriate status code and JSON body