Class AxiomException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BadGatewayException, BadRequestException, ConflictException, ForbiddenException, GatewayTimeoutException, GoneException, InternalServerErrorException, LengthRequiredException, MethodNotAllowedException, NotAcceptableException, NotFoundException, NotImplementedException, PayloadTooLargeException, PreconditionFailedException, PreconditionRequiredException, RequestHeaderFieldsTooLargeException, RequestTimeoutException, ServiceUnavailableException, TooManyRequestsException, UnauthorizedException, UnprocessableContentException, UnsupportedMediaTypeException, UriTooLongException

public abstract class AxiomException extends RuntimeException
Base type for failures that the framework maps to a client-visible error response.

An Axiom exception carries only a final status (400-599), a short machine-readable code and, for some subtypes, a list of field violations. These are the only values that reach the response body, so they must never contain client input, internal messages or class names. Codes are restricted to lowercase ASCII letters, digits, _, . and - (at most 64 characters, starting with a letter) and are validated at construction. The exception message is derived from the status and code alone. The only response headers an exception can add are Allow, Retry-After and WWW-Authenticate, built by subtypes from typed values and validated so they cannot inject other header fields. A cause attached with Throwable.initCause(Throwable) is available to logging but is never sent to clients.

See Also:
  • Constructor Details

    • AxiomException

      protected AxiomException(int status)
      Creates the exception with the status's default code, for example not_found.
      Parameters:
      status - client or server error status, 400 through 599
      Throws:
      IllegalArgumentException - for an invalid status
    • AxiomException

      protected AxiomException(int status, String code)
      Creates the exception.
      Parameters:
      status - client or server error status, 400 through 599
      code - safe machine-readable code
      Throws:
      IllegalArgumentException - for an invalid status or code
    • AxiomException

      protected AxiomException(int status, String code, Map<String,String> headers)
      Creates the exception with response headers.
      Parameters:
      status - client or server error status, 400 through 599
      code - safe machine-readable code
      headers - values for Allow, Retry-After or WWW-Authenticate only; visible ASCII, spaces and tabs, at most 1024 characters each
      Throws:
      IllegalArgumentException - for an invalid status, code, header name or value
  • Method Details

    • status

      public final int status()
      Returns the response status.
      Returns:
      status between 400 and 599
    • code

      public final String code()
      Returns the safe machine-readable code sent to clients.
      Returns:
      error code
    • violations

      public List<Violation> violations()
      Returns field-level details sent to clients; empty unless a subtype provides them.
      Returns:
      immutable violations
    • headers

      public final Map<String,String> headers()
      Returns the headers this exception adds to its error response.
      Returns:
      immutable, case-insensitive headers; empty for most exceptions