...
Creating new methods to validate the new errors is good because it will allow the validation of specific attributes (for example: err.extensions?.rbiErrorDomain
) without needing to use the feature flag or the optional creation.
How?
The new interface IRbiError
and new methods will be parseGraphQLRBIError
and parseGraphQLRBIError
:
IRbiError
Expand |
---|
title | IRbiError interface details |
---|
|
Code Block |
---|
| export interface IRbiError {
errorCode: string;
rbiErrorCode: string;
rbiErrorDomain: string;
statusCode: string;
message: string;
} |
|
mapRBIErrors
path: intl-whitelabel-app/workspaces/frontend/src/utils/errors/index.ts
Expand |
---|
title | mapRBIErrors details |
---|
|
Code Block |
---|
/**
* Maps GraphQL errors to a specific RbiError2IRbiError format.
*
* This function filters and transforms GraphQL errors based on the presence
* of the 'rbiErrorDomain' field in the error's extensions. If the 'rbiErrorDomain'
* is present, the error is transformed into the RbiError2IRbiError format
*
* @param err - The GraphQL error object to be transformed.
* @returns A transformed error object in RbiError2IRbiError format if applicable, otherwise undefined.
*/
const mapRBIErrors = filterMap<GQLError, NonNullableObject<GQLError>, RbiError2>IRbiError>(
err => !!err.extensions?.rbiErrorDomain,
err => {
const { code, rbiErrorCode, rbiErrorDomain, statusCode } = err.extensions || {};
return {
errorCode: code,
rbiErrorCode,
rbiErrorDomain,
statusCode,
message: err?.message,
} as RbiError2IRbiError;
}
); |
|
parseGraphQLRBIError
...
Expand |
---|
title | parseGraphQLRBIError details |
---|
|
Code Block |
---|
| /**
* Parses a GraphQL error, returning an array of RbiError2IRbiError objects.
* If the error is an ApolloError, it uses the graphQLErrors; otherwise, it falls back on originalError.
*
* @param error - The GraphQL error to parse.
* @returns An array of RbiError2IRbiError objects.
*/
export function parseGraphQLRBIError(error: GraphQLError | ApolloError): RbiError2IRbiError[] {
if (isApolloError(error)) {
return mapRBIErrors(error.graphQLErrors);
}
return mapRBIErrors(error.originalError || []);
} |
|
...
Expand |
---|
title | mapRBIErrors details |
---|
|
Code Block |
---|
| const mapRBIErrors = filterMap<GQLError, NonNullableObject<GQLError>, RbiError2>IRbiError>(
err => _FEATURE_FLAG_VALUE_ && !!err.extensions?.rbiErrorDomain,
err => {
const { code, rbiErrorCode, rbiErrorDomain, statusCode } = err.extensions || {};
return {
errorCode: code,
rbiErrorCode,
rbiErrorDomain,
statusCode,
message: err?.message,
} as RbiError2IRbiError;
}
); |
|
In addition of creating the new methods mapRBIErrors and parseGraphQLRBIError, it will need to create the other methods:
...