mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Fix eslint (#46)
* Fix mobile image upload and paste with improved file type handling * Replace older sessions header with separator line * Add ESLint no-console rules and fix lint errors - Add eslint configuration for backend with no-console rule - Add reusable error type guard utility - Replace all error: any with error: unknown and type guards across backend - Update logger to use console.warn/console.error only - Remove unused variables and dead code functions - Fix regex escape characters - Update AGENTS.md with lint commands and requirements
This commit is contained in:
1 parent
c9bf962ac0
commit
8166044d6e
23 files changed
+642
-334
No files matched your search
@@ -0,0 +1,34 @@
|
||||
export function isError(error: unknown): error is Error {
|
||||
return error instanceof Error
|
||||
}
|
||||
|
||||
export function getErrorMessage(error: unknown): string {
|
||||
if (isError(error)) {
|
||||
return error.message
|
||||
}
|
||||
return String(error)
|
||||
}
|
||||
|
||||
export function getErrorStack(error: unknown): string | undefined {
|
||||
if (isError(error)) {
|
||||
return error.stack
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
interface ErrorWithStatusCode {
|
||||
statusCode?: number
|
||||
status?: number
|
||||
}
|
||||
|
||||
const VALID_STATUS_CODES = new Set([200, 201, 204, 301, 302, 304, 400, 401, 403, 404, 405, 409, 413, 422, 500, 501, 502, 503])
|
||||
|
||||
export function getStatusCode(error: unknown): number {
|
||||
let code = 500
|
||||
if (error && typeof error === 'object' && 'statusCode' in error) {
|
||||
code = (error as ErrorWithStatusCode).statusCode || 500
|
||||
} else if (error && typeof error === 'object' && 'status' in error) {
|
||||
code = (error as ErrorWithStatusCode).status || 500
|
||||
}
|
||||
return VALID_STATUS_CODES.has(code) ? code : 500
|
||||
}
|
||||
Reference in new issue
Block a user