Skip to content

HTTPError

Josh Wright edited this page Jan 14, 2021 · 4 revisions

HTTPError

An HTTPError that can be thrown during routing. When intercepted, Alchemy will return an error response with the status code of this error and a body containing the message, if there is one.

public struct HTTPError: Error, ResponseConvertible

Note that if you conform your own, custom Errors to ResponseConvertible, they will be converted to that response if they are thrown during the Router chain.

Usage:

app.post("/error") {
    // Client will see a 501 response status with body
    // { "message": "This endpoint isn't implemented yet" }
    throw HTTPError(.notImplemented, "This endpoint isn't implemented yet")
}

Inheritance

Error, ResponseConvertible

Initializers

init(_:message:)

Create the error with a custom HTTPResponseStatus and optional message.

public init(_ status: HTTPResponseStatus, message: String? = nil)

Parameters

  • status: The status code of this error.
  • message: The message associated with this error, defaults to nil.

Properties

status

The status code of this error.

let status: HTTPResponseStatus

message

An optional message to include in a

let message: String?

Methods

convert()

public func convert() throws -> EventLoopFuture<Response>
Alchemy
Types
Protocols
Global Typealiases
Global Variables
Global Functions
Fusion
Types
Protocols
Papyrus
Types
Protocols
Clone this wiki locally