Add error structuring to Grape API

This commit is contained in:
Karl Erik Õunapuu 2020-10-07 14:17:53 +03:00
parent 01004b8ed4
commit dc8551807a
No known key found for this signature in database
GPG key ID: C9DD647298A34764
3 changed files with 31 additions and 9 deletions

View file

@ -3,6 +3,14 @@ module Repp
format :json
prefix :repp
rescue_from Grape::Exceptions::ValidationErrors do |e|
messages = e.full_messages
errors = []
messages.each { |m| errors << { code: 2003, message: m } }
error!({ errors: errors }, 400)
end
http_basic do |username, password|
@current_user ||= ApiUser.find_by(username: username, plain_text_password: password)
if @current_user