Skip to content

class Athena::Framework::Exception::HTTPException
inherits Exception #

Represents an HTTP error.

Each child represents a specific HTTP error with the associated status code. Also optionally allows adding headers to the resulting response.

Can be used directly/inherited from to represent non-typical HTTP errors/codes.

Included modules

Athena::Framework::Exception

Direct known subclasses

Athena::Framework::Exception::BadGateway Athena::Framework::Exception::BadRequest Athena::Framework::Exception::Conflict Athena::Framework::Exception::Forbidden Athena::Framework::Exception::Gone Athena::Framework::Exception::LengthRequired Athena::Framework::Exception::MethodNotAllowed Athena::Framework::Exception::NotAcceptable Athena::Framework::Exception::NotFound Athena::Framework::Exception::NotImplemented Athena::Framework::Exception::PreconditionFailed Athena::Framework::Exception::ServiceUnavailable Athena::Framework::Exception::TooManyRequests Athena::Framework::Exception::Unauthorized Athena::Framework::Exception::UnprocessableEntity Athena::Framework::Exception::UnsupportedMediaType

Constructors#

.from_status(status : Int32 | HTTP::Status, message : String = "", cause : ::Exception | Nil = nil, headers : HTTP::Headers = HTTP::Headers.new) : self#

Helper method to return the proper exception subclass for the provided status. The message, cause, and headers are passed along as well if provided.

ameba:disable Metrics/CyclomaticComplexity

View source

.new(status : HTTP::Status, message : String, cause : ::Exception | Nil = nil, headers : HTTP::Headers = HTTP::Headers.new)#

Instantiates self with the given status and message.

Optionally includes cause, and headers.

View source

.new(status_code : Int32, message : String, cause : ::Exception | Nil = nil, headers : HTTP::Headers = HTTP::Headers.new)#

Instantiates self with the given status_code and message.

Optionally includes cause, and headers.

View source

Methods#

#headers : HTTP::Headers#

Any HTTP response headers associated with self.

Some HTTP errors use response headers to give additional information about self.

View source

#headers=(headers : HTTP::Headers)#

Any HTTP response headers associated with self.

Some HTTP errors use response headers to give additional information about self.

View source

#status : HTTP::Status#

The HTTP::Status associated with self.

View source

#status_code : Int32#

Returns the HTTP status code of #status.

View source

#to_json(builder : JSON::Builder) : Nil#

Serializes self to JSON in the format of {"code":400,"message":"Exception message"}

View source