-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc718da
commit ab72151
Showing
2 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import {expect, test} from 'vitest'; | ||
import {APIErrorContext, CartoAPIError} from '@carto/api-client'; | ||
|
||
[ | ||
{ | ||
title: '400 error', | ||
error: new Error('Bad'), | ||
errorContext: {requestType: 'Map data'}, | ||
response: {status: 400}, | ||
message: ` | ||
Map data API request failed | ||
Server returned: Bad request (400): Bad | ||
`, | ||
}, | ||
{ | ||
title: '401 error', | ||
error: new Error('Unauthorized'), | ||
errorContext: {requestType: 'Map data'}, | ||
response: {status: 401}, | ||
message: ` | ||
Map data API request failed | ||
Server returned: Unauthorized access (401): Unauthorized | ||
`, | ||
}, | ||
{ | ||
title: '403 error', | ||
error: new Error('Forbidden'), | ||
errorContext: {requestType: 'Map data'}, | ||
response: {status: 403}, | ||
message: ` | ||
Map data API request failed | ||
Server returned: Unauthorized access (403): Forbidden | ||
`, | ||
}, | ||
{ | ||
title: '404 error', | ||
error: new Error('Not found'), | ||
errorContext: {requestType: 'Map data'}, | ||
response: {status: 404}, | ||
message: ` | ||
Map data API request failed | ||
Server returned: Not found (404): Not found | ||
`, | ||
}, | ||
{ | ||
title: '500 error', | ||
error: new Error('Source error'), | ||
errorContext: {requestType: 'Map data'}, | ||
response: {status: 500}, | ||
message: ` | ||
Map data API request failed | ||
Server returned: Error (500): Source error | ||
`, | ||
}, | ||
{ | ||
title: 'Full error context: instantiation', | ||
error: new Error('Source error'), | ||
errorContext: { | ||
requestType: 'Map instantiation', | ||
connection: 'connectionName', | ||
source: 'sourceName', | ||
type: 'query', | ||
}, | ||
response: {status: 500}, | ||
message: ` | ||
Map instantiation API request failed | ||
Server returned: Error (500): Source error | ||
Connection: connectionName | ||
Source: sourceName | ||
Type: query | ||
`, | ||
}, | ||
{ | ||
title: 'Full error context: public map', | ||
error: new Error('Source error'), | ||
errorContext: { | ||
requestType: 'Public map', | ||
mapId: 'abcd', | ||
}, | ||
response: {status: 500}, | ||
message: ` | ||
Public map API request failed | ||
Server returned: Error (500): Source error | ||
Map Id: abcd | ||
`, | ||
}, | ||
{ | ||
title: 'Full error context: custom value', | ||
error: new Error('Source error'), | ||
errorContext: { | ||
requestType: 'Tile stats', | ||
connection: 'connectionName', | ||
source: 'sourceName', | ||
type: 'tileset', | ||
customKey: 'customValue', | ||
}, | ||
response: {status: 500}, | ||
message: ` | ||
Tile stats API request failed | ||
Server returned: Error (500): Source error | ||
Connection: connectionName | ||
Source: sourceName | ||
Type: tileset | ||
Custom Key: customValue | ||
`, | ||
}, | ||
].forEach(({title, error, errorContext, response, message}) => { | ||
test(`CartoAPIError: ${title}`, () => { | ||
const cartoAPIError = new CartoAPIError( | ||
error, | ||
errorContext as APIErrorContext, | ||
response as Response | ||
); | ||
expect(cartoAPIError).toBeTruthy(); | ||
expect(cartoAPIError.message).toBe(message.slice(1)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters