🚨 Handle errors easily in Vapor
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


CI Status Swift 4.1 Twitter

🤨 What is this?

A helper framework for handling API errors in Vapor. This framework is meant to be used in a client-to-server communication situation and not for services that render web pages to users. This framework makes it easy for clients to handle errors more gracefully than an ordinary call (i.e. an iOS app calling an API and be able to handle the error sent from the API server).

📝 Requirements

Name Minimum version
Swift 4.1
Vapor 3.0

📲 Installation


Add the following to your Package.swift file:

.package(url: "https://github.com/menly/api-error.git", from: "1.0.0")

⌨️ Usage

  1. Import the framework:

     import APIError
  2. Register the provider in your Vapor configure method:

     try services.register(APIErrorProvider())
  3. Register the middleware:

     var middlewares = MiddlewareConfig()

Make sure to register this middleware as the first middleware, and don't use the standard Vapor error middleware as they can conflict.

Now it's easy to create errors for your API - and sent the correct information to the client. Make your errors conform to the AbortError protocol, and use:

throw CustomError.SomeError

Then the response, if there is an error, will be:

  "error": true,
  "identifier": "SomeErrorIdentifier",
  "message": "There was some error from our awesome API"

👋 Get in touch!

Get in touch with us! Send us an email, say hi on twitter (@menlyhq) or check out our website.

📄 License

See the license file for more information.

The names and logos for Menly and their products are trademarks of Menly ApS.

Copyright (c) Menly ApS 2016-present.