diff --git a/libs/driver/magento/src/errors/transform-graphql.spec.ts b/libs/driver/magento/src/errors/transform-graphql.spec.ts index 2fc8e971db..f0c61609db 100644 --- a/libs/driver/magento/src/errors/transform-graphql.spec.ts +++ b/libs/driver/magento/src/errors/transform-graphql.spec.ts @@ -1,5 +1,3 @@ -import { ApolloError } from '@apollo/client/core'; - import { DaffError, DaffErrorCodeMap, @@ -60,6 +58,12 @@ describe('@daffodil/driver/magento | daffMagentoTransformGraphQlError', () => { }); it('should not crash if the extension is not defined', () => { + const { extensions, ...error } = unhandledGraphQlError; + expect(() => daffMagentoTransformGraphQlError(error, map)).not.toThrow(); + expect(daffMagentoTransformGraphQlError(error, map)).toEqual(new DaffDriverMagentoError('An error we don\'t handle')); + }); + + it('should not crash if there are no extensions defined', () => { const error = { ...unhandledGraphQlError, extensions: {}}; expect(() => daffMagentoTransformGraphQlError(error, map)).not.toThrow(); }); diff --git a/libs/driver/magento/src/errors/transform-graphql.ts b/libs/driver/magento/src/errors/transform-graphql.ts index 0ea549a653..c67fd06345 100644 --- a/libs/driver/magento/src/errors/transform-graphql.ts +++ b/libs/driver/magento/src/errors/transform-graphql.ts @@ -11,7 +11,7 @@ export function daffMagentoTransformGraphQlError( error: GraphQLError, map: T, ): DaffError { - const ErrorClass = map[error.extensions.category] || DaffDriverMagentoError; + const ErrorClass = map[error?.extensions?.category] || DaffDriverMagentoError; return new ErrorClass(error.message) ; };