Skip to content

Commit 64e9ce3

Browse files
authored
fix(driver): allow undefined extensions key in Magento graphql responses (#3087)
In Magento versions that support GraphQl prior to v2.4.6 there was a key errors called "extensions" that contained an error code indicating what kind of error you received. For whatever reason, in v2.4.6 they removed this. Once you upgrade to v2.4.6, without this patch you will see errors like `Cannot read properties of undefined (reading 'category')` as a result.
1 parent b5a39df commit 64e9ce3

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

libs/driver/magento/src/errors/transform-graphql.spec.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { ApolloError } from '@apollo/client/core';
2-
31
import {
42
DaffError,
53
DaffErrorCodeMap,
@@ -60,6 +58,12 @@ describe('@daffodil/driver/magento | daffMagentoTransformGraphQlError', () => {
6058
});
6159

6260
it('should not crash if the extension is not defined', () => {
61+
const { extensions, ...error } = unhandledGraphQlError;
62+
expect(() => daffMagentoTransformGraphQlError(error, map)).not.toThrow();
63+
expect(daffMagentoTransformGraphQlError(error, map)).toEqual(new DaffDriverMagentoError('An error we don\'t handle'));
64+
});
65+
66+
it('should not crash if there are no extensions defined', () => {
6367
const error = { ...unhandledGraphQlError, extensions: {}};
6468
expect(() => daffMagentoTransformGraphQlError(error, map)).not.toThrow();
6569
});

libs/driver/magento/src/errors/transform-graphql.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function daffMagentoTransformGraphQlError<T extends DaffErrorCodeMap>(
1111
error: GraphQLError,
1212
map: T,
1313
): DaffError {
14-
const ErrorClass = map[error.extensions.category] || DaffDriverMagentoError;
14+
const ErrorClass = map[error?.extensions?.category] || DaffDriverMagentoError;
1515

1616
return new ErrorClass(error.message) ;
1717
};

0 commit comments

Comments
 (0)