diff --git a/CHANGELOG.md b/CHANGELOG.md index 23f50a31..8910c0c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ### Unreleased +* Treat 207 Multi-Status responses as successful, so a response that carries partial results is returned instead of raising an error * Documented `tracking_options.domain_name` hash support for custom link and open tracking hostnames. See the [message tracking documentation](https://developer.nylas.com/docs/v3/email/message-tracking/) * Documented Contact `metadata` and `metadata_pair` hashes, and added `contact.updated` and `contact.deleted` webhook trigger constants diff --git a/lib/nylas/errors.rb b/lib/nylas/errors.rb index ebb14f86..a72eafdc 100644 --- a/lib/nylas/errors.rb +++ b/lib/nylas/errors.rb @@ -83,5 +83,5 @@ def initialize(url, timeout) end end - HTTP_SUCCESS_CODES = [200, 201, 202, 302].freeze + HTTP_SUCCESS_CODES = [200, 201, 202, 207, 302].freeze end diff --git a/spec/nylas/handler/http_client_spec.rb b/spec/nylas/handler/http_client_spec.rb index 2d39db42..a47bbb1f 100644 --- a/spec/nylas/handler/http_client_spec.rb +++ b/spec/nylas/handler/http_client_spec.rb @@ -704,6 +704,21 @@ class TestHttpClient "https://test.api.nylas.com/foo") end.not_to raise_error end + + it "does not raise an error for a 207 Multi-Status response" do + response = { + request_id: "request-id", + data: { + recording: { url: "https://test.storage/recording.mp4" }, + errors: [{ artifact: "summary", code: "generation_failed" }] + } + } + + expect do + http_client.send(:handle_failed_response, 207, response, + "https://test.api.nylas.com/foo") + end.not_to raise_error + end end describe "#parse_json_evaluate_error" do @@ -719,6 +734,19 @@ class TestHttpClient "https://test.api.nylas.com/foo", "application/json")).to eq(response) end + it "returns the parsed response for a 207 Multi-Status response" do + response = { + request_id: "request-id", + data: { + recording: { url: "https://test.storage/recording.mp4" }, + errors: [{ artifact: "summary", code: "generation_failed" }] + } + } + + expect(http_client.send(:parse_json_evaluate_error, 207, response.to_json, + "https://test.api.nylas.com/foo", "application/json")).to eq(response) + end + it "raises a Nylas::JsonParseError if the response is not valid JSON" do response = "foo"