|
291 | 291 | end |
292 | 292 |
|
293 | 293 | describe "failed request handling" do |
| 294 | + context "receive 413 response" do |
| 295 | + let(:string_io) { StringIO.new } |
| 296 | + |
| 297 | + before do |
| 298 | + configuration.sdk_logger = Logger.new(string_io) |
| 299 | + end |
| 300 | + |
| 301 | + context "with response body" do |
| 302 | + let(:fake_response) { build_fake_response("413", body: { detail: "Envelope too large" }) } |
| 303 | + |
| 304 | + it "raises SizeExceededError with body in message" do |
| 305 | + sentry_stub_request(fake_response) |
| 306 | + |
| 307 | + expect { subject.send_data(data) }.to raise_error( |
| 308 | + Sentry::SizeExceededError, |
| 309 | + /HTTP 413: Envelope dropped due to exceeded size limit.*body:.*Envelope too large/ |
| 310 | + ) |
| 311 | + end |
| 312 | + |
| 313 | + it "logs a warning message with body" do |
| 314 | + sentry_stub_request(fake_response) |
| 315 | + |
| 316 | + expect { subject.send_data(data) }.to raise_error(Sentry::SizeExceededError) |
| 317 | + expect(string_io.string).to include("HTTP 413: Envelope dropped due to exceeded size limit") |
| 318 | + expect(string_io.string).to include("Envelope too large") |
| 319 | + end |
| 320 | + end |
| 321 | + |
| 322 | + context "with empty response body" do |
| 323 | + let(:fake_response) do |
| 324 | + Net::HTTPResponse.new("1.0", "413", "").tap do |response| |
| 325 | + allow(response).to receive(:body).and_return("") |
| 326 | + end |
| 327 | + end |
| 328 | + |
| 329 | + it "raises SizeExceededError without body in message" do |
| 330 | + sentry_stub_request(fake_response) |
| 331 | + |
| 332 | + expect { subject.send_data(data) }.to raise_error( |
| 333 | + Sentry::SizeExceededError, |
| 334 | + "HTTP 413: Envelope dropped due to exceeded size limit" |
| 335 | + ) |
| 336 | + end |
| 337 | + end |
| 338 | + |
| 339 | + context "records client reports via send_envelope" do |
| 340 | + let(:fake_response) { build_fake_response("413", body: { detail: "too large" }) } |
| 341 | + |
| 342 | + it "records send_error for each item in the envelope" do |
| 343 | + sentry_stub_request(fake_response) |
| 344 | + |
| 345 | + configuration.send_client_reports = true |
| 346 | + transport = Sentry::HTTPTransport.new(configuration) |
| 347 | + envelope = transport.envelope_from_event(event) |
| 348 | + |
| 349 | + transport.send_envelope(envelope) |
| 350 | + |
| 351 | + # Should have recorded send_error for the event item |
| 352 | + expect(transport.discarded_events[[:send_error, "error"]]).to eq(1) |
| 353 | + end |
| 354 | + |
| 355 | + it "does not raise the error to the caller" do |
| 356 | + sentry_stub_request(fake_response) |
| 357 | + |
| 358 | + configuration.send_client_reports = true |
| 359 | + transport = Sentry::HTTPTransport.new(configuration) |
| 360 | + envelope = transport.envelope_from_event(event) |
| 361 | + |
| 362 | + expect { transport.send_envelope(envelope) }.not_to raise_error |
| 363 | + end |
| 364 | + end |
| 365 | + end |
| 366 | + |
294 | 367 | context "receive 4xx responses" do |
295 | 368 | let(:fake_response) { build_fake_response("404") } |
296 | 369 |
|
|
0 commit comments