Skip to content

Commit 0ea7691

Browse files
committed
Add clickable links to error messages and permission helper
- Use webLink() for Socket.dev URLs (settings, pricing, status) - Use githubRepoLink() for GitHub issue links - Import terminal-link helpers for consistent clickable URLs - Makes all URLs in error messages clickable in supported terminals
1 parent 53f1a06 commit 0ea7691

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/utils/api.mts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
debugHttpError,
3333
} from './debug.mts'
3434
import { buildErrorCause } from './errors.mts'
35+
import { githubRepoLink, webLink } from './terminal-link.mts'
3536
import constants, {
3637
CONFIG_KEY_API_BASE_URL,
3738
EMPTY_VALUE,
@@ -92,7 +93,9 @@ function logPermissionsFor403(cmdPath?: string | undefined): void {
9293
}
9394
logger.error('')
9495
logger.error('💡 To fix this:')
95-
logger.error(' 1. Visit https://socket.dev/settings/api-tokens')
96+
logger.error(
97+
` 1. Visit ${webLink('https://socket.dev/settings/api-tokens')}`,
98+
)
9699
logger.error(
97100
' 2. Edit your API token to grant the permissions listed above',
98101
)
@@ -127,9 +130,9 @@ export async function getErrorMessageForHttpStatusCode(code: number) {
127130
'❌ Access denied: Your API token lacks required permissions or organization access.\n' +
128131
'💡 Try:\n' +
129132
' • Run `socket whoami` to verify your account and organization\n' +
130-
' • Check your API token permissions at https://socket.dev/settings/api-tokens\n' +
133+
` • Check your API token permissions at ${webLink('https://socket.dev/settings/api-tokens')}\n` +
131134
" • Ensure you're accessing the correct organization with `--org` flag\n" +
132-
' • Verify your plan includes this feature at https://socket.dev/pricing'
135+
` • Verify your plan includes this feature at ${webLink('https://socket.dev/pricing')}`
133136
)
134137
}
135138
if (code === HTTP_STATUS_NOT_FOUND) {
@@ -139,14 +142,14 @@ export async function getErrorMessageForHttpStatusCode(code: number) {
139142
' • Verify resource names (package, repository, organization)\n' +
140143
' • Check if the resource was deleted or moved\n' +
141144
' • Update to the latest CLI version: `socket self-update` (SEA) or `npm update -g socket`\n' +
142-
' • Report persistent issues at https://github.com/SocketDev/socket-cli/issues'
145+
` • Report persistent issues at ${githubRepoLink('SocketDev', 'socket-cli', 'issues')}`
143146
)
144147
}
145148
if (code === HTTP_STATUS_TOO_MANY_REQUESTS) {
146149
return (
147150
'❌ Rate limit exceeded: Too many API requests.\n' +
148151
'💡 Try:\n' +
149-
' • Free plan: Wait a few minutes for quota reset or upgrade at https://socket.dev/pricing\n' +
152+
` • Free plan: Wait a few minutes for quota reset or upgrade at ${webLink('https://socket.dev/pricing')}\n` +
150153
' • Paid plan: Contact support if rate limits seem incorrect\n' +
151154
' • Check current quota: `socket organization quota`\n' +
152155
' • Reduce request frequency or batch operations'
@@ -157,13 +160,13 @@ export async function getErrorMessageForHttpStatusCode(code: number) {
157160
'❌ Server error: Socket API encountered an internal problem (HTTP 500).\n' +
158161
'💡 Try:\n' +
159162
' • Wait a few minutes and retry your command\n' +
160-
' • Check Socket status: https://status.socket.dev\n' +
161-
' • Report persistent issues: https://github.com/SocketDev/socket-cli/issues'
163+
` • Check Socket status: ${webLink('https://status.socket.dev')}\n` +
164+
` • Report persistent issues: ${githubRepoLink('SocketDev', 'socket-cli', 'issues')}`
162165
)
163166
}
164167
return (
165168
`❌ HTTP ${code}: Server responded with unexpected status code.\n` +
166-
'💡 Try: Check Socket status at https://status.socket.dev or report the issue.'
169+
`💡 Try: Check Socket status at ${webLink('https://status.socket.dev')} or report the issue.`
167170
)
168171
}
169172

0 commit comments

Comments
 (0)