Skip to content

Commit 1f6879d

Browse files
authored
Merge pull request #311 from jamesstonehill/raise-on-misc-client-error
Raise client error for unhandled 4xx responses
2 parents a34e285 + 0fecb2f commit 1f6879d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- [#311](https://githup.com/JsonApiClient/json_api_client/pull/311) - Raise JsonApiClient::Errors::ClientError for unhandled 4xx responses
6+
57
## v1.6.1
68

79
- [#297](https://githup.com/JsonApiClient/json_api_client/pull/297) - Fix test_helper

lib/json_api_client/middleware/status.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def handle_status(code, env)
2929
when 409
3030
raise Errors::Conflict, env
3131
when 400..499
32-
# some other error
32+
raise Errors::ClientError, env
3333
when 500..599
3434
raise Errors::ServerError, env
3535
else

test/unit/status_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,17 @@ def test_server_responding_with_404_status_meta
5656
end
5757
end
5858

59+
def test_server_responding_with_408_status
60+
stub_request(:get, "http://example.com/users/1")
61+
.to_return(headers: {content_type: "application/vnd.api+json"}, body: {
62+
meta: {
63+
status: 408,
64+
message: "Request timeout"
65+
}
66+
}.to_json)
67+
68+
assert_raises JsonApiClient::Errors::ClientError do
69+
User.find(1)
70+
end
71+
end
5972
end

0 commit comments

Comments
 (0)