Make returned API errors more consistent

This commit is contained in:
Maciej Szlosarczyk 2018-08-07 15:04:37 +03:00
parent de9b1517b0
commit 0798001725
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
2 changed files with 4 additions and 4 deletions

View file

@ -31,7 +31,7 @@ module Api
if @contact
render json: @contact
else
render json: { errors: ['Contact not found'] }, status: :not_found
render json: { errors: [{ base: ['Contact not found'] }] }, status: :not_found
end
end

View file

@ -50,7 +50,7 @@ class RegistrantApiContactsTest < ActionDispatch::IntegrationTest
assert_equal(401, response.status)
json_body = JSON.parse(response.body, symbolize_names: true)
assert_equal({ errors: ['Not authorized'] }, json_body)
assert_equal({ errors: [base: ['Not authorized']] }, json_body)
end
def test_details_returns_401_without_authorization
@ -58,7 +58,7 @@ class RegistrantApiContactsTest < ActionDispatch::IntegrationTest
assert_equal(401, response.status)
json_body = JSON.parse(response.body, symbolize_names: true)
assert_equal({ errors: ['Not authorized'] }, json_body)
assert_equal({ errors: [base: ['Not authorized']] }, json_body)
end
def test_details_returns_404_for_non_existent_contact
@ -66,7 +66,7 @@ class RegistrantApiContactsTest < ActionDispatch::IntegrationTest
assert_equal(404, response.status)
json_body = JSON.parse(response.body, symbolize_names: true)
assert_equal({ errors: ['Contact not found'] }, json_body)
assert_equal({ errors: [base: ['Contact not found']] }, json_body)
end
private