|
5 | 5 | 'HTTParty::Response', |
6 | 6 | code: 500, |
7 | 7 | headers: { 'Key' => 'Value' }, |
8 | | - body: '{ "message": "Internal Server Error" }', |
| 8 | + body: '{ "Message": "An error has occured.", "ExceptionMessage": "orders are required", "ExceptionType": "System.ArgumentException" }', |
9 | 9 | ) |
10 | 10 |
|
11 | 11 | error = described_class.from_response(response) |
12 | 12 |
|
13 | 13 | expect(error).to have_attributes( |
14 | 14 | response_code: 500, |
15 | 15 | response_headers: { 'Key' => 'Value' }, |
16 | | - response_body: '{ "message": "Internal Server Error" }', |
| 16 | + response_body: '{ "Message": "An error has occured.", "ExceptionMessage": "orders are required", "ExceptionType": "System.ArgumentException" }', |
17 | 17 | ) |
18 | 18 | end |
19 | 19 | end |
| 20 | + |
| 21 | + describe '.message' do |
| 22 | + it 'returns the name of the exception if there is no message body' do |
| 23 | + response = instance_double( |
| 24 | + 'HTTParty::Response', |
| 25 | + code: 500, |
| 26 | + headers: { 'Key' => 'Value' }, |
| 27 | + body: nil |
| 28 | + ) |
| 29 | + |
| 30 | + error = described_class.from_response(response) |
| 31 | + |
| 32 | + expect(error.message).to eq("SolidusShipstation::Api::RequestError") |
| 33 | + end |
| 34 | + |
| 35 | + it 'extracts both the ExceptionMessage and ExceptionType' do |
| 36 | + response = instance_double( |
| 37 | + 'HTTParty::Response', |
| 38 | + code: 500, |
| 39 | + headers: { 'Key' => 'Value' }, |
| 40 | + body: '{ "Message": "An error has occured.", "ExceptionMessage": "orders are required", "ExceptionType": "System.ArgumentException" }', |
| 41 | + ) |
| 42 | + |
| 43 | + error = described_class.from_response(response) |
| 44 | + |
| 45 | + expect(error.message).to eq("System.ArgumentException: orders are required") |
| 46 | + end |
| 47 | + |
| 48 | + it 'doesn\'t fail when the ExceptionMessage and ExceptionType are missing' do |
| 49 | + response = instance_double( |
| 50 | + 'HTTParty::Response', |
| 51 | + code: 500, |
| 52 | + headers: { 'Key' => 'Value' }, |
| 53 | + body: '{ "Message": "An error has occured." }', |
| 54 | + ) |
| 55 | + |
| 56 | + error = described_class.from_response(response) |
| 57 | + |
| 58 | + expect(error.message).to eq("Unknown Exception Type: ") |
| 59 | + end |
| 60 | + end |
20 | 61 | end |
0 commit comments