Skip to content

fix: generic template title max length error - #1583

Merged
mohamedhassanmn merged 14 commits into
developfrom
1514
Jul 1, 2026
Merged

fix: generic template title max length error#1583
mohamedhassanmn merged 14 commits into
developfrom
1514

Conversation

@mohamedhassanmn

@mohamedhassanmn mohamedhassanmn commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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:

  • Attempting to create a generic template with input values exceeding the allowed database length.
  • Verifying that the backend correctly catches the database error.
  • Confirming that a user-friendly GraphQL error message is returned instead of the raw database error.

Fixes

Fixes #1514

Changes

  • Added error handling in the generic template creation flow.
  • Added a conditional check for database errors containing value too long.
  • Return a custom GraphQLError with a clearer error message when field length validation fails.
  • Preserved existing error handling behavior for all other errors.

Depends on

No dependencies.

Tests included/Docs Updated?

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@mohamedhassanmn
mohamedhassanmn requested a review from a team as a code owner June 16, 2026 12:26
@mohamedhassanmn
mohamedhassanmn requested review from a team, ACLay and martin-trajanovski and removed request for a team June 16, 2026 12:26
@mohamedhassanmn mohamedhassanmn changed the title fix: generic template title too long db error message to human readab… fix: Generic template title max length error Jun 17, 2026
@mohamedhassanmn
mohamedhassanmn requested review from a team and bolmsten and removed request for a team and martin-trajanovski June 17, 2026 08:07
@mohamedhassanmn mohamedhassanmn changed the title fix: Generic template title max length error fix: generic template title max length error Jun 17, 2026
})
.catch((err) => {
if (err.message.includes('value too long')) {
return new GraphQLError(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be:

"throw new GraphQLError("

?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to throw the error, not return the error object. I have no idea what that would cause

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread apps/backend/src/mutations/GenericTemplateMutations.ts

@zacharyjhankin zacharyjhankin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change

return err;
if (err.message.includes('value too long')) {
throw new GraphQLError(
'Failed to insert genericTemplate as the value is too long'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, thanks. I’ll update the error message to make it more user-friendly and avoid exposing the internal genericTemplate terminology.

@mohamedhassanmn
mohamedhassanmn merged commit 877952b into develop Jul 1, 2026
21 checks passed
@mohamedhassanmn
mohamedhassanmn deleted the 1514 branch July 1, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generic template title max length error

3 participants