Skip to content

Commit 91064d1

Browse files
authored
Merge pull request #312 from jamesstonehill/422-error-handling
Do not raise errors on 422 responses
2 parents 118fa6c + 99d1de5 commit 91064d1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/json_api_client/middleware/status.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def handle_status(code, env)
2828
raise Errors::NotFound, env[:url]
2929
when 409
3030
raise Errors::Conflict, env
31+
when 422
32+
# Allow to proceed as resource errors will be populated
3133
when 400..499
3234
raise Errors::ClientError, env
3335
when 500..599

test/unit/status_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,16 @@ def test_server_responding_with_408_status
6969
User.find(1)
7070
end
7171
end
72+
73+
def test_server_responding_with_422_status
74+
stub_request(:get, "http://example.com/users/1")
75+
.to_return(headers: {content_type: "application/vnd.api+json"}, body: {
76+
meta: {
77+
status: 422
78+
}
79+
}.to_json)
80+
81+
# We want to test that this response does not raise an error
82+
User.find(1)
83+
end
7284
end

0 commit comments

Comments
 (0)