-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add exceptions and handler for query builder and runner #6043
Conversation
throw new TimeoutError(error.message); | ||
} | ||
|
||
throw error; |
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.
Should we throw InternalServerError
here?
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.
PR Summary
- Added custom exceptions for query builder and runner
- Replaced generic errors with specific exceptions in factories
- Introduced centralized error handler for workspace resolvers
- Enhanced error logging in
workspace-query-runner.service.ts
- Improved error management in resolver factories with
workspaceResolverErrorHandler
29 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings
@@ -0,0 +1,5 @@ | |||
export class RecordsNotFoundException extends Error { | |||
constructor(ids?: string[]) { | |||
super(`Records ${ids} not found`); |
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.
🧠 logic: Consider handling the case where ids
is undefined or an empty array to avoid potential issues with the error message.
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.
Mmm, I'm not sure of this approach, I feel like we will create a lot of classes if we want to be that specific.
What about creating a more higher level Error class like FieldError and specify via an ErrorCode like GraphqlError?
Something like this where you can still keep some information such as the httpCode
custom-error.ts
interface ErrorExtension {
internalCode?: string;
httpCode: number;
}
abstract class CustomError extends Error {
public extension: ErrorExtension;
constructor(message: string, internalCode: string, errorExtension: ErrorExtension) {
super(message);
this.extension = {
...errorExtension,
internalCode,
};
this.name = this.constructor.name;
}
}
field.error.ts
enum FieldErrorCode {
FIELD_NOT_FOUND = 'FIELD_NOT_FOUND',
FIELD_ALREADY_EXISTS = 'FIELD_ALREADY_EXISTS',
}
const FieldErrorDetails: Record<FieldErrorCode, ErrorExtension> = {
[FieldErrorCode.FIELD_NOT_FOUND]: {
httpCode: 404,
},
[FieldErrorCode.FIELD_ALREADY_EXISTS]: {
httpCode: 409,
},
};
class FieldError extends CustomError {
constructor(message: string, internalCode: FieldErrorCode) {
super(message, internalCode, FieldErrorDetails[internalCode]);
}
}
and test like this where you have access to the internalCode or the httpCode for exception handler logic
try {
throw new FieldError(
'The specified field was not found.',
FieldErrorCode.FIELD_NOT_FOUND,
);
} catch (error) {
if (error instanceof FieldError) {
switch (error.extension.internalCode) {
case FieldErrorCode.FIELD_NOT_FOUND:
console.log('Field not found');
break;
case FieldErrorCode.FIELD_ALREADY_EXISTS:
console.log('Field already exists');
break;
default:
console.log('Unknown field error:', error.message);
}
} else {
console.error('Handle generic error:', error);
}
}
I haven't tested it, not sure this is 100% what we want or if it's not too overkill but I feel like this should fit our needs?
If we don't want httpCode in the error and let the code that catch the code handle this, we can simple replace FieldErrorDetails by an enum instead.
cc @thomtrp @charlesBochet
As title