Improve error handling (#13130)

In the BE we throw custom errors with precise error codes (e.g.
"LABEL_ALREADY_EXISTS") before catching them in filters and rethrowing
BaseGraphQLErrors (standard errors such as NotFoundError, UserInputError
etc.).
In the FE we were grouping sentries based on the error codes but we were
actually grouping by very broad codes such as "NOT_FOUND" or
"BAD_USER_INPUT", extracted from the BaseGraphQLErrors.

To fix that, we update the BaseGraphQLError constructor api to allow to
pass on the CustomError directly and retrieve from it the original code
and store it in existing property `subCode` that we will use in the FE
to send errors to sentry.
This new api also eases usage of `userFriendlyMessage` that is passed on
to the api response and therefore to the FE when CustomError is passed
on directly to the BaseGraphQLError constructor.
This commit is contained in:
Marie
2025-07-09 17:13:44 +02:00
committed by GitHub
parent 484c267aa6
commit c13bc60dad
22 changed files with 319 additions and 123 deletions

View File

@ -5,6 +5,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "CONFLICTING_PHONE_CALLING_CODE_AND_COUNTRY_CODE",
"userFriendlyMessage": "Provided country code and calling code are conflicting",
},
"message": "Provided country code and calling code are conflicting",
@ -18,6 +19,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "CONFLICTING_PHONE_CALLING_CODE_AND_COUNTRY_CODE",
"userFriendlyMessage": "Provided country code and calling code are conflicting",
},
"message": "Provided country code and calling code are conflicting",
@ -31,6 +33,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "CONFLICTING_PHONE_CALLING_CODE",
"userFriendlyMessage": "Provided and inferred calling code are conflicting",
},
"message": "Provided and inferred calling code are conflicting",
@ -44,6 +47,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "CONFLICTING_PHONE_CALLING_CODE",
"userFriendlyMessage": "Provided and inferred calling code are conflicting",
},
"message": "Provided and inferred calling code are conflicting",
@ -57,6 +61,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "CONFLICTING_PHONE_COUNTRY_CODE",
"userFriendlyMessage": "Provided and inferred country code are conflicting",
},
"message": "Provided and inferred country code are conflicting",
@ -70,6 +75,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "CONFLICTING_PHONE_COUNTRY_CODE",
"userFriendlyMessage": "Provided and inferred country code are conflicting",
},
"message": "Provided and inferred country code are conflicting",
@ -83,6 +89,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "INVALID_PHONE_CALLING_CODE",
"userFriendlyMessage": "Invalid calling code +999",
},
"message": "Invalid calling code +999",
@ -96,6 +103,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "INVALID_PHONE_CALLING_CODE",
"userFriendlyMessage": "Invalid calling code +999",
},
"message": "Invalid calling code +999",
@ -109,6 +117,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "INVALID_PHONE_COUNTRY_CODE",
"userFriendlyMessage": "Invalid country code XX",
},
"message": "Invalid country code XX",
@ -122,6 +131,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "INVALID_PHONE_COUNTRY_CODE",
"userFriendlyMessage": "Invalid country code XX",
},
"message": "Invalid country code XX",
@ -135,6 +145,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "INVALID_PHONE_NUMBER",
"userFriendlyMessage": "Provided phone number is invalid not-a-number",
},
"message": "Provided phone number is invalid not-a-number",
@ -148,6 +159,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "INVALID_PHONE_NUMBER",
"userFriendlyMessage": "Provided phone number is invalid not-a-number",
},
"message": "Provided phone number is invalid not-a-number",
@ -161,6 +173,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "INVALID_PHONE_NUMBER",
"userFriendlyMessage": "Provided phone number is invalid 123456789",
},
"message": "Provided phone number is invalid 123456789",
@ -174,6 +187,7 @@ exports[`Phone field metadata tests suite It should fail to create primary phone
{
"extensions": {
"code": "BAD_USER_INPUT",
"subCode": "INVALID_PHONE_NUMBER",
"userFriendlyMessage": "Provided phone number is invalid 123456789",
},
"message": "Provided phone number is invalid 123456789",