Vapor Documentation Beta

Structure Abort

public struct Abort: AbortError, DebuggableError

Default implementation of AbortError. You can use this as a convenient method for throwing AbortErrors without having to conform your own error-type to AbortError.

throw Abort(.badRequest, reason: "Something's not quite right...")
%3 Abort Abort AbortError AbortError Abort->AbortError DebuggableError DebuggableError Abort->DebuggableError

Conforms To

AbortError

Errors conforming to this protocol will always be displayed by Vapor to the end-user (even in production mode where most errors are silenced).

DebuggableError

Debuggable provides an interface that allows a type to be more easily debugged in the case of an error.

Initializers

init(_:​headers:​reason:​identifier:​suggested​Fixes:​file:​function:​line:​column:​range:​stack​Trace:​)

public init(_ status: HTTPResponseStatus, headers: HTTPHeaders = [:], reason: String? = nil, identifier: String? = nil, suggestedFixes: [String] = [], file: String = #file, function: String = #function, line: UInt = #line, column: UInt = #column, range: Range<UInt>? = nil, stackTrace: StackTrace? = .capture(skip: 1))

Create a new Abort, capturing current source location info.

Properties

identifier

var identifier: String

See Debuggable

status

var status: HTTPResponseStatus

See AbortError

headers

var headers: HTTPHeaders

See AbortError.

reason

var reason: String

See AbortError

source

var source: ErrorSource?

Source location where this error was created.

stack​Trace

var stackTrace: StackTrace?

Stack trace at point of error creation.

Methods

redirect(to:​type:​)

public static func redirect(to location: String, type: RedirectType = .normal) -> Abort

Creates a redirecting Abort error.

throw Abort.redirect(to: "https://vapor.codes")"

Set type to '.permanently' to allow caching to automatically redirect from browsers. Defaulting to non-permanent to prevent unexpected caching.