Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(driver): allow undefined extensions key in Magento graphql responses #3087

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions libs/driver/magento/src/errors/transform-graphql.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ApolloError } from '@apollo/client/core';

import {
DaffError,
DaffErrorCodeMap,
Expand Down Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion libs/driver/magento/src/errors/transform-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function daffMagentoTransformGraphQlError<T extends DaffErrorCodeMap>(
error: GraphQLError,
map: T,
): DaffError {
const ErrorClass = map[error.extensions.category] || DaffDriverMagentoError;
const ErrorClass = map[error?.extensions?.category] || DaffDriverMagentoError;

return new ErrorClass(error.message) ;
};
Loading