ml-archive / error-extended

Vapor errors with more granularity.
MIT License
6 stars 1 forks source link
error error-reporting re server-side-swift swift vapor vapor-2

ErrorExtended

Swift Version Vapor Version Circle CI codebeat badge codecov Readme Score GitHub license

Vapor errors with more granularity.

šŸ“¦ Installation

Update your Package.swift file.

.Package(url: "https://github.com/nodes-vapor/error-extended.git", majorVersion: 1)

Getting started šŸš€

import ErrorExtended

If you need more granular control on the content that goes into your errors conforming to the AbortError protocol you can use the AbortExtended type instead (which conforms to AbortError). This type will give you access to all of the parameters as well as providing you with some convenient extra parameters.

A couple of examples:

throw AbortExtended.custom(code: 1337)
throw AbortExtended.custom(
  status: .badRequest, 
  code: 1337, 
  message: "Sorry, bad request", 
  report: false
)
throw AbortExtended.custom(
  status: .badGateway, 
  code: Status.badGateway.statusCode, 
  message: Status.badGateway.reasonPhrase, 
  metadata: Node(["key": "value"]), 
  report: false
)

Any middleware (e.g. bugsnag) that tries to catch errors conforming to AbortError will then pick this up.

šŸ† Credits

This package is developed and maintained by the Vapor team at Nodes. The package owner for this project is Rasmus.

šŸ“„ License

This package is open-sourced software licensed under the MIT license