1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Puma::ErrorHandler, feature_category: :shared do
subject { described_class.new(is_production) }
let(:is_production) { true }
let(:ex) { StandardError.new('Sample error message') }
let(:env) { {} }
let(:status_code) { 500 }
describe '#execute' do
it 'captures the exception and returns a Rack response' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
ex,
{ puma_env: env, status_code: status_code },
{ handler: 'puma_low_level' }
).and_call_original
status, headers, message = subject.execute(ex, env, status_code)
expect(status).to eq(500)
expect(headers).to eq({})
expect(message).to eq(described_class::PROD_ERROR_MESSAGE)
end
context 'when not in production' do
let(:is_production) { false }
it 'returns a Rack response with dev error message' do
status, headers, message = subject.execute(ex, env, status_code)
expect(status).to eq(500)
expect(headers).to eq({})
expect(message).to eq(described_class::DEV_ERROR_MESSAGE)
end
end
context 'when status code is nil' do
let(:status_code) { 500 }
it 'defaults to error 500' do
status, headers, message = subject.execute(ex, env, status_code)
expect(status).to eq(500)
expect(headers).to eq({})
expect(message).to eq(described_class::PROD_ERROR_MESSAGE)
end
end
context 'when status code is provided' do
let(:status_code) { 404 }
it 'uses the provided status code in the response' do
status, headers, message = subject.execute(ex, env, status_code)
expect(status).to eq(404)
expect(headers).to eq({})
expect(message).to eq(described_class::PROD_ERROR_MESSAGE)
end
end
end
end
|