mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
- Added package.json for OneUptime CLI with scripts for development and build processes. - Included TypeScript configuration (tsconfig.json) with strict type checking and module settings.
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import { printError } from "./OutputFormatter";
|
|
|
|
export enum ExitCode {
|
|
Success = 0,
|
|
GeneralError = 1,
|
|
AuthError = 2,
|
|
NotFound = 3,
|
|
}
|
|
|
|
export function handleError(error: unknown): never {
|
|
if (error instanceof Error) {
|
|
const message: string = error.message;
|
|
|
|
// Check for auth-related errors
|
|
if (
|
|
message.includes("API key") ||
|
|
message.includes("credentials") ||
|
|
message.includes("Unauthorized") ||
|
|
message.includes("401")
|
|
) {
|
|
printError(`Authentication error: ${message}`);
|
|
process.exit(ExitCode.AuthError);
|
|
}
|
|
|
|
// Check for not found errors
|
|
if (message.includes("404") || message.includes("not found")) {
|
|
printError(`Not found: ${message}`);
|
|
process.exit(ExitCode.NotFound);
|
|
}
|
|
|
|
// General API errors
|
|
if (message.includes("API error")) {
|
|
printError(message);
|
|
process.exit(ExitCode.GeneralError);
|
|
}
|
|
|
|
printError(`Error: ${message}`);
|
|
} else {
|
|
printError(`Error: ${String(error)}`);
|
|
}
|
|
|
|
process.exit(ExitCode.GeneralError);
|
|
}
|