|
20 | 20 | */ |
21 | 21 |
|
22 | 22 | import { messageWithCauses } from 'pony-cause' |
| 23 | +import colors from 'yoctocolors-cjs' |
23 | 24 |
|
24 | 25 | import { logger } from '@socketsecurity/registry/lib/logger' |
25 | 26 | import { isNonEmptyString } from '@socketsecurity/registry/lib/strings' |
@@ -87,12 +88,12 @@ function logPermissionsFor403(cmdPath?: string | undefined): void { |
87 | 88 | } |
88 | 89 |
|
89 | 90 | logger.error('') |
90 | | - logger.error('🔐 Required API Permissions:') |
| 91 | + logger.error(`🔐 ${colors.yellow('Required API Permissions')}:`) |
91 | 92 | for (const permission of requirements.permissions) { |
92 | | - logger.error(` • ${permission}`) |
| 93 | + logger.error(` • ${colors.cyan(permission)}`) |
93 | 94 | } |
94 | 95 | logger.error('') |
95 | | - logger.error('💡 To fix this:') |
| 96 | + logger.error(`💡 ${colors.cyan('To fix this')}:`) |
96 | 97 | logger.error( |
97 | 98 | ` 1. Visit ${webLink('https://socket.dev/settings/api-tokens')}`, |
98 | 99 | ) |
@@ -121,52 +122,52 @@ export function getDefaultApiBaseUrl(): string | undefined { |
121 | 122 | export async function getErrorMessageForHttpStatusCode(code: number) { |
122 | 123 | if (code === HTTP_STATUS_BAD_REQUEST) { |
123 | 124 | return ( |
124 | | - '❌ Invalid request: One of the options or parameters may be incorrect.\n' + |
125 | | - '💡 Try: Check your command syntax and parameter values.' |
| 125 | + `❌ ${colors.red('Invalid request')}: One of the options or parameters may be incorrect.\n` + |
| 126 | + `💡 ${colors.cyan('Try')}: Check your command syntax and parameter values.` |
126 | 127 | ) |
127 | 128 | } |
128 | 129 | if (code === HTTP_STATUS_FORBIDDEN || code === HTTP_STATUS_UNAUTHORIZED) { |
129 | 130 | return ( |
130 | | - '❌ Access denied: Your API token lacks required permissions or organization access.\n' + |
131 | | - '💡 Try:\n' + |
132 | | - ' • Run `socket whoami` to verify your account and organization\n' + |
| 131 | + `❌ ${colors.red('Access denied')}: Your API token lacks required permissions or organization access.\n` + |
| 132 | + `💡 ${colors.cyan('Try')}:\n` + |
| 133 | + ` • Run ${colors.bold('socket whoami')} to verify your account and organization\n` + |
133 | 134 | ` • Check your API token permissions at ${webLink('https://socket.dev/settings/api-tokens')}\n` + |
134 | | - " • Ensure you're accessing the correct organization with `--org` flag\n" + |
| 135 | + ` • Ensure you're accessing the correct organization with ${colors.bold('--org')} flag\n` + |
135 | 136 | ` • Verify your plan includes this feature at ${webLink('https://socket.dev/pricing')}` |
136 | 137 | ) |
137 | 138 | } |
138 | 139 | if (code === HTTP_STATUS_NOT_FOUND) { |
139 | 140 | return ( |
140 | | - "❌ Not found: The requested endpoint or resource doesn't exist.\n" + |
141 | | - '💡 Try:\n' + |
| 141 | + `❌ ${colors.red('Not found')}: The requested endpoint or resource doesn't exist.\n` + |
| 142 | + `💡 ${colors.cyan('Try')}:\n` + |
142 | 143 | ' • Verify resource names (package, repository, organization)\n' + |
143 | 144 | ' • Check if the resource was deleted or moved\n' + |
144 | | - ' • Update to the latest CLI version: `socket self-update` (SEA) or `npm update -g socket`\n' + |
| 145 | + ` • Update to the latest CLI version: ${colors.bold('socket self-update')} (SEA) or ${colors.bold('npm update -g socket')}\n` + |
145 | 146 | ` • Report persistent issues at ${githubRepoLink('SocketDev', 'socket-cli', 'issues')}` |
146 | 147 | ) |
147 | 148 | } |
148 | 149 | if (code === HTTP_STATUS_TOO_MANY_REQUESTS) { |
149 | 150 | return ( |
150 | | - '❌ Rate limit exceeded: Too many API requests.\n' + |
151 | | - '💡 Try:\n' + |
152 | | - ` • Free plan: Wait a few minutes for quota reset or upgrade at ${webLink('https://socket.dev/pricing')}\n` + |
153 | | - ' • Paid plan: Contact support if rate limits seem incorrect\n' + |
154 | | - ' • Check current quota: `socket organization quota`\n' + |
| 151 | + `❌ ${colors.red('Rate limit exceeded')}: Too many API requests.\n` + |
| 152 | + `💡 ${colors.cyan('Try')}:\n` + |
| 153 | + ` • ${colors.yellow('Free plan')}: Wait a few minutes for quota reset or upgrade at ${webLink('https://socket.dev/pricing')}\n` + |
| 154 | + ` • ${colors.yellow('Paid plan')}: Contact support if rate limits seem incorrect\n` + |
| 155 | + ` • Check current quota: ${colors.bold('socket organization quota')}\n` + |
155 | 156 | ' • Reduce request frequency or batch operations' |
156 | 157 | ) |
157 | 158 | } |
158 | 159 | if (code === HTTP_STATUS_INTERNAL_SERVER_ERROR) { |
159 | 160 | return ( |
160 | | - '❌ Server error: Socket API encountered an internal problem (HTTP 500).\n' + |
161 | | - '💡 Try:\n' + |
| 161 | + `❌ ${colors.red('Server error')}: Socket API encountered an internal problem (HTTP 500).\n` + |
| 162 | + `💡 ${colors.cyan('Try')}:\n` + |
162 | 163 | ' • Wait a few minutes and retry your command\n' + |
163 | 164 | ` • Check Socket status: ${webLink('https://status.socket.dev')}\n` + |
164 | 165 | ` • Report persistent issues: ${githubRepoLink('SocketDev', 'socket-cli', 'issues')}` |
165 | 166 | ) |
166 | 167 | } |
167 | 168 | return ( |
168 | | - `❌ HTTP ${code}: Server responded with unexpected status code.\n` + |
169 | | - `💡 Try: Check Socket status at ${webLink('https://status.socket.dev')} or report the issue.` |
| 169 | + `❌ ${colors.red(`HTTP ${code}`)}: Server responded with unexpected status code.\n` + |
| 170 | + `💡 ${colors.cyan('Try')}: Check Socket status at ${webLink('https://status.socket.dev')} or report the issue.` |
170 | 171 | ) |
171 | 172 | } |
172 | 173 |
|
|
0 commit comments