Make API return errors array

This commit is contained in:
Maciej Szlosarczyk 2018-07-30 11:07:44 +03:00
parent ed1afb78f6
commit c1ea79615f
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
4 changed files with 5 additions and 5 deletions

View file

@ -46,7 +46,7 @@ module Api
allowed_ips = ENV['registrant_api_auth_allowed_ips'].to_s.split(',').map(&:strip) allowed_ips = ENV['registrant_api_auth_allowed_ips'].to_s.split(',').map(&:strip)
return if allowed_ips.include?(request.ip) || Rails.env.development? return if allowed_ips.include?(request.ip) || Rails.env.development?
render json: { error: 'Not authorized' }, status: :unauthorized render json: { errors: ['Not authorized'] }, status: :unauthorized
end end
end end
end end

View file

@ -29,7 +29,7 @@ module Api
if decryptor.valid? if decryptor.valid?
sign_in decryptor.user sign_in decryptor.user
else else
render json: { error: 'Not authorized' }, status: :unauthorized render json: { errors: ['Not authorized'] }, status: :unauthorized
end end
end end
end end

View file

@ -42,7 +42,7 @@ class RegistrantApiAuthenticationTest < ActionDispatch::IntegrationTest
assert_equal(401, response.status) assert_equal(401, response.status)
json_body = JSON.parse(response.body, symbolize_names: true) json_body = JSON.parse(response.body, symbolize_names: true)
assert_equal({error: 'Not authorized'}, json_body) assert_equal({ errors: ['Not authorized'] }, json_body)
ENV['registrant_api_auth_allowed_ips'] = @original_whitelist_ip ENV['registrant_api_auth_allowed_ips'] = @original_whitelist_ip
end end
@ -52,7 +52,7 @@ class RegistrantApiAuthenticationTest < ActionDispatch::IntegrationTest
post '/api/v1/registrant/auth/eid', params post '/api/v1/registrant/auth/eid', params
json = JSON.parse(response.body, symbolize_names: true) json = JSON.parse(response.body, symbolize_names: true)
assert_equal({errors: [{ident: ['parameter is required']}]}, json) assert_equal({ errors: [{ ident: ['parameter is required'] }] }, json)
assert_equal(422, response.status) assert_equal(422, response.status)
end end
end end

View file

@ -19,7 +19,7 @@ class RegistrantApiDomainsTest < ActionDispatch::IntegrationTest
assert_equal(401, response.status) assert_equal(401, response.status)
json_body = JSON.parse(response.body, symbolize_names: true) json_body = JSON.parse(response.body, symbolize_names: true)
assert_equal({error: 'Not authorized'}, json_body) assert_equal({ errors: ['Not authorized'] }, json_body)
end end
private private