An open API service indexing awesome lists of open source software.

https://github.com/roxasshadow/sinatra-error

Error handling in Sinatra like Grape
https://github.com/roxasshadow/sinatra-error

Last synced: over 1 year ago
JSON representation

Error handling in Sinatra like Grape

Awesome Lists containing this project

README

          

Sinatra::Error
=============================
Error handling in Sinatra like Grape.

-----------------------------

Like in Grape, now you can do this in Sinatra

`$ gem install sinatra-error`

```ruby
require 'sinatra'
require 'sinatra/error'

# parameters:
# message => String or Hash with the output
# status => Integer (default 403)
# format => Symbol (default :json)

error!({ 'error' => 'unauthorized', 'detail' => 'login required' }, 401) unless logged?
# {"error":"unauthorized","detail":"login required"}
error!('unauthorized', 401) unless logged?
# {"error":"unauthorized"}
error!('unauthorized', 401, :txt) unless logged?
# unauthorized
```