-
Notifications
You must be signed in to change notification settings - Fork 14
HTTPError
Josh Wright edited this page Jan 14, 2021
·
4 revisions
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 Error
s 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")
}
Error
, ResponseConvertible
Create the error with a custom HTTPResponseStatus
and
optional message.
public init(_ status: HTTPResponseStatus, message: String? = nil)
- status: The status code of this error.
- message: The message associated with this error, defaults to nil.
The status code of this error.
let status: HTTPResponseStatus
An optional message to include in a
let message: String?
public func convert() throws -> EventLoopFuture<Response>
Generated at 2021-01-13T22:24:59-0800 using swift-doc 1.0.0-beta.5.
Alchemy
Types
- AlterTableBuilder
- BCryptDigest
- BasicAuthMiddleware
- BcryptError
- BelongsToRelationship
- CORSMiddleware
- CORSMiddleware.AllowOriginSetting
- CORSMiddleware.Configuration
- ColumnType
- CreateColumn
- CreateColumnBuilder
- CreateIndex
- CreateTableBuilder
- DatabaseConfig
- DatabaseError
- DatabaseField
- DatabaseKeyMappingStrategy
- DatabaseValue
- DayUnit
- Env
- FrequencyTyped
- Grammar
- HTTPAuth
- HTTPAuth.Basic
- HTTPAuth.Bearer
- HTTPBody
- HTTPError
- HasManyRelationship
- HasOneRelationship
- HasRelationship
- HourUnit
- JoinClause
- JoinType
- Launch
- Log
- MIMEType
- MinuteUnit
- ModelQuery
- MySQLDatabase
- Operator
- OrderClause
- OrderClause.Sort
- OrderedDictionary
- PapyrusClientError
- PathParameter
- PathParameter.DecodingError
- PostgresDatabase
- Query
- Request
- Response
- Router
- RuneError
- SQL
- SQLJSON
- Scheduler
- Schema
- SecondUnit
- Services
- Socket
- StaticFileMiddleware
- StringLength
- Thread
- TokenAuthMiddleware
- WeekUnit
- Weekday
- WhereBoolean
- WhereColumn
- WhereIn
- WhereIn.InType
- WhereNested
- WhereRaw
- WhereValue