Skip to content

Commit e17a510

Browse files
authored
feat: include request URL in API error messages (#1094)
Surface the failing endpoint URL in API error messages so users can quickly identify which request failed. Uses the new `url` field from @socketsecurity/sdk 1.4.96 for SDK-routed calls and appends the path for direct-fetch calls in queryApiSafeText and sendApiRequest.
1 parent f67b088 commit e17a510

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [1.1.65](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.65) - 2026-02-26
8+
9+
### Changed
10+
- Improved API error messages to include the request URL, making it easier to debug which endpoint failed
11+
712
## [1.1.64](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.64) - 2026-02-25
813

914
### Changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "socket",
3-
"version": "1.1.64",
3+
"version": "1.1.65",
44
"description": "CLI for Socket.dev",
55
"homepage": "https://github.com/SocketDev/socket-cli",
66
"license": "MIT AND OFL-1.1",
@@ -122,7 +122,7 @@
122122
"@socketregistry/packageurl-js": "1.0.9",
123123
"@socketsecurity/config": "3.0.1",
124124
"@socketsecurity/registry": "1.1.17",
125-
"@socketsecurity/sdk": "1.4.95",
125+
"@socketsecurity/sdk": "1.4.96",
126126
"@socketsecurity/socket-patch": "1.2.0",
127127
"@types/blessed": "0.1.25",
128128
"@types/cmd-shim": "5.0.2",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/api.mts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,11 @@ export async function handleApiCall<T extends SocketSdkOperations>(
195195
const errStr = errCResult.error ? String(errCResult.error).trim() : ''
196196
const message = errStr || NO_ERROR_MESSAGE
197197
const reason = errCResult.cause || NO_ERROR_MESSAGE
198-
const cause =
198+
const baseCause =
199199
reason && message !== reason ? `${message} (reason: ${reason})` : message
200+
const cause = errCResult.url
201+
? `${baseCause} (url: ${errCResult.url})`
202+
: baseCause
200203
const socketSdkErrorResult: ApiCallResult<T> = {
201204
ok: false,
202205
message: 'Socket API error',
@@ -254,8 +257,11 @@ export async function handleApiCallNoSpinner<T extends SocketSdkOperations>(
254257
: ''
255258
const message = errStr || NO_ERROR_MESSAGE
256259
const reason = sdkErrorResult.cause || NO_ERROR_MESSAGE
257-
const cause =
260+
const baseCause =
258261
reason && message !== reason ? `${message} (reason: ${reason})` : message
262+
const cause = sdkErrorResult.url
263+
? `${baseCause} (url: ${sdkErrorResult.url})`
264+
: baseCause
259265

260266
return {
261267
ok: false,
@@ -348,12 +354,13 @@ export async function queryApiSafeText(
348354
const errStr = e ? String(e).trim() : ''
349355
const message = 'API request failed'
350356
const rawCause = errStr || NO_ERROR_MESSAGE
351-
const cause = message !== rawCause ? rawCause : ''
357+
const baseCause = message !== rawCause ? rawCause : ''
358+
const cause = baseCause ? `${baseCause} (path: ${path})` : `(path: ${path})`
352359

353360
return {
354361
ok: false,
355362
message,
356-
...(cause ? { cause } : {}),
363+
cause,
357364
}
358365
}
359366

@@ -366,7 +373,7 @@ export async function queryApiSafeText(
366373
return {
367374
ok: false,
368375
message: 'Socket API error',
369-
cause: `${result.statusText} (reason: ${await getErrorMessageForHttpStatusCode(status)})`,
376+
cause: `${result.statusText} (reason: ${await getErrorMessageForHttpStatusCode(status)}) (path: ${path})`,
370377
data: {
371378
code: status,
372379
},
@@ -386,7 +393,7 @@ export async function queryApiSafeText(
386393
return {
387394
ok: false,
388395
message: 'API request failed',
389-
cause: 'Unexpected error reading response text',
396+
cause: `Unexpected error reading response text (path: ${path})`,
390397
}
391398
}
392399
}
@@ -495,12 +502,13 @@ export async function sendApiRequest<T>(
495502
const errStr = e ? String(e).trim() : ''
496503
const message = 'API request failed'
497504
const rawCause = errStr || NO_ERROR_MESSAGE
498-
const cause = message !== rawCause ? rawCause : ''
505+
const baseCause = message !== rawCause ? rawCause : ''
506+
const cause = baseCause ? `${baseCause} (path: ${path})` : `(path: ${path})`
499507

500508
return {
501509
ok: false,
502510
message,
503-
...(cause ? { cause } : {}),
511+
cause,
504512
}
505513
}
506514

@@ -513,7 +521,7 @@ export async function sendApiRequest<T>(
513521
return {
514522
ok: false,
515523
message: 'Socket API error',
516-
cause: `${result.statusText} (reason: ${await getErrorMessageForHttpStatusCode(status)})`,
524+
cause: `${result.statusText} (reason: ${await getErrorMessageForHttpStatusCode(status)}) (path: ${path})`,
517525
data: {
518526
code: status,
519527
},
@@ -532,7 +540,7 @@ export async function sendApiRequest<T>(
532540
return {
533541
ok: false,
534542
message: 'API request failed',
535-
cause: 'Unexpected error parsing response JSON',
543+
cause: `Unexpected error parsing response JSON (path: ${path})`,
536544
}
537545
}
538546
}

0 commit comments

Comments
 (0)