berget 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +6 -0
- package/TODO.md +17 -0
- package/dist/index.js +447 -8
- package/dist/src/client.js +148 -0
- package/dist/src/services/api-key-service.js +114 -0
- package/dist/src/services/auth-service.js +168 -0
- package/dist/src/services/cluster-service.js +55 -0
- package/dist/src/services/collaborator-service.js +37 -0
- package/dist/src/services/flux-service.js +37 -0
- package/dist/src/services/helm-service.js +37 -0
- package/dist/src/services/kubectl-service.js +43 -0
- package/dist/src/utils/error-handler.js +45 -0
- package/index.ts +545 -12
- package/package.json +13 -7
- package/src/client.ts +133 -0
- package/src/services/api-key-service.ts +114 -0
- package/src/services/auth-service.ts +206 -0
- package/src/services/cluster-service.ts +50 -0
- package/src/services/collaborator-service.ts +34 -0
- package/src/services/flux-service.ts +37 -0
- package/src/services/helm-service.ts +37 -0
- package/src/services/kubectl-service.ts +33 -0
- package/src/types/api.d.ts +2037 -0
- package/src/utils/error-handler.ts +40 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Formats and prints error messages in a consistent way
|
|
5
|
+
*/
|
|
6
|
+
export function handleError(message: string, error: any): void {
|
|
7
|
+
console.error(chalk.red(`Error: ${message}`));
|
|
8
|
+
|
|
9
|
+
// If the error is a string (like JSON.stringify(error))
|
|
10
|
+
if (typeof error === 'string') {
|
|
11
|
+
try {
|
|
12
|
+
// Try to parse it as JSON
|
|
13
|
+
const parsedError = JSON.parse(error);
|
|
14
|
+
if (parsedError.error) {
|
|
15
|
+
console.error(chalk.dim(`Details: ${parsedError.error}`));
|
|
16
|
+
if (parsedError.code) {
|
|
17
|
+
console.error(chalk.dim(`Code: ${parsedError.code}`));
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
console.error(chalk.dim(`Details: ${error}`));
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
// If it's not valid JSON, just print the string
|
|
24
|
+
console.error(chalk.dim(`Details: ${error}`));
|
|
25
|
+
}
|
|
26
|
+
} else if (error && error.message) {
|
|
27
|
+
// If it's an Error object
|
|
28
|
+
console.error(chalk.dim(`Details: ${error.message}`));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Check for authentication errors
|
|
32
|
+
if (
|
|
33
|
+
(typeof error === 'string' && error.includes('Unauthorized')) ||
|
|
34
|
+
(error && error.message && error.message.includes('Unauthorized')) ||
|
|
35
|
+
(error && error.code && error.code === 401)
|
|
36
|
+
) {
|
|
37
|
+
console.error(chalk.yellow('\nYou need to be logged in to use this command.'));
|
|
38
|
+
console.error(chalk.yellow('Run `berget login` to authenticate.'));
|
|
39
|
+
}
|
|
40
|
+
}
|