-
Notifications
You must be signed in to change notification settings - Fork 1
Add API, harden build scripts #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f3894d8
43544ed
b3af705
a05a543
e0ce38e
c650071
8a391ae
acc5a3a
10ece2c
0153f0c
acde9d8
021a227
07181b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,26 +31,37 @@ export function errorHandler( | |
| ): void { | ||
| const errorId = generateErrorId(); | ||
|
|
||
| // Extract error properties with safe type handling. | ||
| // We accept Error | unknown and need to safely access properties that may exist | ||
| // on Error objects (message), HTTP error objects (statusCode, status), or custom | ||
| // error objects (code). Type casting to any is necessary to access these | ||
| // arbitrary properties while maintaining runtime safety through optional chaining. | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const errorObj = err as any; // Allow accessing arbitrary properties | ||
| const errorMessage = errorObj?.message ?? String(err); | ||
| const errorType = errorObj?.constructor?.name ?? 'Unknown'; | ||
| const statusCode = errorObj?.statusCode ?? errorObj?.status ?? 500; | ||
| const errorCode = errorObj?.code; | ||
|
|
||
| // Log the full error internally with correlation ID (safe location) | ||
| log.error({ | ||
| message: 'API error', | ||
| data: { | ||
| errorId, | ||
| type: err?.constructor?.name || 'Unknown', | ||
| message: err?.message || String(err) | ||
| type: errorType, | ||
| message: errorMessage | ||
| } | ||
| }); | ||
|
|
||
| // Return safe error response to client with error ID for tracing | ||
| const statusCode = err?.statusCode || err?.status || 500; | ||
| const errorResponse: ErrorResponse = { | ||
| error: 'An error occurred processing your request', | ||
| errorId | ||
| }; | ||
|
|
||
| // Add code if it's a validation error or known error type | ||
| if (err?.code) { | ||
| errorResponse.code = err.code; | ||
| if (errorCode) { | ||
| errorResponse.code = errorCode; | ||
| } | ||
|
|
||
| res.status(statusCode).json(errorResponse); | ||
|
Comment on lines
56
to
67
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment indicates this is a duplicate build step and acknowledges it's redundant. Having duplicate build steps increases CI time and resource usage unnecessarily. Consider implementing the suggested solution of ensuring the build-and-push job only runs after successful test/lint steps, or add a dedicated build job that both test and build-and-push depend on. The TODO should be resolved rather than leaving duplicate steps in production.