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
- Host: GitHub
- URL: https://github.com/roxasshadow/sinatra-error
- Owner: RoxasShadow
- Created: 2012-02-14T14:57:43.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2013-12-18T01:39:22.000Z (over 12 years ago)
- Last Synced: 2025-02-08T02:45:01.157Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 97.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
```