fix: generic template title max length error#1583
Conversation
| }) | ||
| .catch((err) => { | ||
| if (err.message.includes('value too long')) { | ||
| return new GraphQLError( |
There was a problem hiding this comment.
Shouldn't this be:
"throw new GraphQLError("
?
There was a problem hiding this comment.
We want to throw the error, not return the error object. I have no idea what that would cause
There was a problem hiding this comment.
Good catch, you’re right. Returning the error object here would resolve the promise instead of propagating the failure. I’ll update it to throw so the error is handled correctly upstream.
There was a problem hiding this comment.
Updated this as suggested to throw the error from the datasource. I found that the resolver catch was overriding the custom GraphQLError with the generic rejection message, so I added a check to preserve GraphQLError instances and only wrap unexpected errors.
| return err; | ||
| if (err.message.includes('value too long')) { | ||
| throw new GraphQLError( | ||
| 'Failed to insert genericTemplate as the value is too long' |
There was a problem hiding this comment.
I think it might be more helpful to say something like title too long as a user does not know the name genericTemplate as it is never used in the frontend
There was a problem hiding this comment.
That makes sense, thanks. I’ll update the error message to make it more user-friendly and avoid exposing the internal genericTemplate terminology.
Description
This PR improves error handling when creating a generic template by catching database errors caused by values exceeding the allowed field length and returning a more meaningful GraphQL error message.
Motivation and Context
Previously, when attempting to insert a generic template with a value exceeding the database field limit, the backend returned the raw database error, making it difficult to understand the actual issue.
This change ensures that such cases are handled gracefully by detecting the specific database error and returning a cleaner and more understandable error message.
How Has This Been Tested
Tested locally by:
Fixes
Fixes #1514
Changes
value too long.GraphQLErrorwith a clearer error message when field length validation fails.Depends on
No dependencies.
Tests included/Docs Updated?