Skip to content

Commit 19b7c2a

Browse files
Include HTTP status code in error messages
1 parent cd845d3 commit 19b7c2a

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

src/tools/MapboxApiBasedTool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ export abstract class MapboxApiBasedTool<
6060
* If the response contains a JSON body with a 'message' field, returns that.
6161
* Otherwise falls back to the response status text.
6262
* @param response The HTTP response object
63-
* @returns The error message string
63+
* @returns The error message string in format "statusCode: message"
6464
*/
6565
protected async getErrorMessage(response: Response): Promise<string> {
6666
try {
6767
const errorBody = await response.text();
6868
const errorJson = JSON.parse(errorBody);
6969
if (errorJson.message) {
70-
return errorJson.message;
70+
return `${response.status}: ${errorJson.message}`;
7171
}
7272
} catch {
7373
// If parsing fails, fall back to status text
7474
}
75-
return response.statusText;
75+
return `${response.status}: ${response.statusText}`;
7676
}
7777

7878
/**

test/tools/category-search-tool/CategorySearchTool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('CategorySearchTool', () => {
114114
expect(result.isError).toBe(true);
115115
expect(result.content[0]).toMatchObject({
116116
type: 'text',
117-
text: 'Category Search API error: Not Found'
117+
text: 'Category Search API error: 404: Not Found'
118118
});
119119
});
120120

test/tools/directions-tool/DirectionsTool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ describe('DirectionsTool', () => {
160160
expect(result.isError).toBe(true);
161161
expect(result.content[0]).toMatchObject({
162162
type: 'text',
163-
text: 'Directions API error: Not Found'
163+
text: 'Directions API error: 404: Not Found'
164164
});
165165
assertHeadersSent(mockHttpRequest);
166166
});

test/tools/matrix-tool/MatrixTool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ describe('MatrixTool', () => {
256256
expect(result.isError).toBe(true);
257257
expect(result.content[0]).toMatchObject({
258258
type: 'text',
259-
text: 'Matrix API error: Not Found'
259+
text: 'Matrix API error: 404: Not Found'
260260
});
261261

262262
assertHeadersSent(mockHttpRequest);

test/tools/reverse-geocode-tool/ReverseGeocodeTool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ describe('ReverseGeocodeTool', () => {
224224
expect(result.isError).toBe(true);
225225
expect(result.content[0]).toMatchObject({
226226
type: 'text',
227-
text: 'Reverse Geocode API error: Not Found'
227+
text: 'Reverse Geocode API error: 404: Not Found'
228228
});
229229
});
230230

test/tools/search-and-geocode-tool/SearchAndGeocodeTool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('SearchAndGeocodeTool', () => {
123123
expect(result.isError).toBe(true);
124124
expect(result.content[0]).toMatchObject({
125125
type: 'text',
126-
text: 'Search API error: Not Found'
126+
text: 'Search API error: 404: Not Found'
127127
});
128128
});
129129

test/tools/static-map-image-tool/StaticMapImageTool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('StaticMapImageTool', () => {
116116
expect(result.isError).toBe(true);
117117
expect(result.content[0]).toMatchObject({
118118
type: 'text',
119-
text: 'Static Map API error: Not Found'
119+
text: 'Static Map API error: 404: Not Found'
120120
});
121121
});
122122

0 commit comments

Comments
 (0)