Swiftpack.co - Package - menly/api-error

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 & copyright

See the license file for more information.

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


Stars: 0
Help us keep the lights on



1.3.0 - Nov 19, 2018

  • Updated source location, so it's always available, because otherwise we risk not triggering a log to Stackdriver

1.2.3 - Nov 9, 2018

1.2.2 - Nov 8, 2018

1.2.1 - Nov 8, 2018

1.2.0 - Nov 8, 2018