Return JSON response from 404

This commit is contained in:
Maciej Szlosarczyk 2020-06-11 13:18:05 +03:00
parent 1033ddc218
commit 7ece2e0341
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
3 changed files with 24 additions and 9 deletions

View file

@ -1,6 +1,8 @@
module Api
module V1
class BaseController < ActionController::API
rescue_from ActiveRecord::RecordNotFound, with: :not_found_error
private
def authenticate
@ -8,6 +10,12 @@ module Api
head :unauthorized unless ip_allowed
end
def not_found_error
uuid = params['uuid']
json = { error: 'Not Found', uuid: uuid, message: 'Record not found' }
render json: json, status: :not_found
end
def allowed_ips
ENV['auction_api_allowed_ips'].split(',').map(&:strip)
end