Skip to content

Commit

Permalink
feat(driver): add DaffDriverNetworkError (#2534)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Aug 10, 2023
1 parent 1569d60 commit 6e30ab1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
5 changes: 5 additions & 0 deletions libs/driver/magento/src/errors/network-error.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import {
DaffInheritableError,
} from '@daffodil/core';

/**
* @deprecated use {@link DaffDriverNetworkError} instead.
*/
export const DAFF_DRIVER_MAGENTO_NETWORK_ERROR_CODE = 'DAFF_DRIVER_MAGENTO_NETWORK_ERROR';

/**
* An error thrown when the Magento driver encountered a problem with network connectivity.
*
* @deprecated use {@link DaffDriverNetworkError} instead.
*/
export class DaffDriverMagentoNetworkError extends DaffInheritableError implements DaffError {
public readonly code: string = DAFF_DRIVER_MAGENTO_NETWORK_ERROR_CODE;
Expand Down
11 changes: 4 additions & 7 deletions libs/driver/magento/src/errors/transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import {
DaffErrorCodeMap,
DaffInheritableError,
} from '@daffodil/core';
import {
DaffDriverMagentoError,
DaffDriverMagentoNetworkError,
DAFF_DRIVER_MAGENTO_NETWORK_ERROR_CODE,
} from '@daffodil/driver/magento';
import { DAFF_DRIVER_NETWORK_ERROR_CODE } from '@daffodil/driver';
import { DaffDriverMagentoError } from '@daffodil/driver/magento';

import { daffTransformMagentoError } from './transform';

Expand Down Expand Up @@ -80,7 +77,7 @@ describe('@daffodil/driver/magento | daffTransformMagentoError', () => {
expect(result).toEqual(jasmine.any(MockError));
});

it('should be able to process Apollo network errors and return the DaffDriverMagentoNetworkError', () => {
it('should be able to process Apollo network errors and return the DaffDriverNetworkError', () => {
const error = new ApolloError({
networkError: {
name: 'Error',
Expand All @@ -89,7 +86,7 @@ describe('@daffodil/driver/magento | daffTransformMagentoError', () => {
});
const result = daffTransformMagentoError(error, map);

expect(result.code).toEqual(DAFF_DRIVER_MAGENTO_NETWORK_ERROR_CODE);
expect(result.code).toEqual(DAFF_DRIVER_NETWORK_ERROR_CODE);
});

describe('when there are no GraphQL error', () => {
Expand Down
4 changes: 2 additions & 2 deletions libs/driver/magento/src/errors/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
DaffErrorCodeMap,
daffIsError,
} from '@daffodil/core';
import { DaffDriverNetworkError } from '@daffodil/driver';

import { DaffDriverMagentoError } from './error.class';
import { DaffDriverMagentoNetworkError } from './network-error.class';
import { daffMagentoTransformGraphQlError } from './transform-graphql';

/**
Expand All @@ -18,7 +18,7 @@ export function daffTransformMagentoError<T extends DaffErrorCodeMap>(error: any
if (error.graphQLErrors?.length > 0) {
return (<ApolloError>error).graphQLErrors.map(err => daffMagentoTransformGraphQlError<T>(err, map))[0];
} else if (error.networkError) {
return new DaffDriverMagentoNetworkError((<ApolloError>error).networkError.message);
return new DaffDriverNetworkError((<ApolloError>error).networkError.message);
} else if (daffIsError(error)) {
return error;
} else {
Expand Down
17 changes: 17 additions & 0 deletions libs/driver/src/errors/network-error.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
DaffError,
DaffInheritableError,
} from '@daffodil/core';

export const DAFF_DRIVER_NETWORK_ERROR_CODE = 'DAFF_DRIVER_NETWORK_ERROR';

/**
* An error thrown when the a driver encounters a problem with network connectivity.
*/
export class DaffDriverNetworkError extends DaffInheritableError implements DaffError {
public readonly code: string = DAFF_DRIVER_NETWORK_ERROR_CODE;

constructor(message?: string) {
super(message);
}
}
4 changes: 4 additions & 0 deletions libs/driver/src/errors/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
export { DaffBadInputError } from './bad-input';
export {
DaffDriverNetworkError,
DAFF_DRIVER_NETWORK_ERROR_CODE,
} from './network-error.class';
export { DaffDriverErrorCodes } from './codes';

0 comments on commit 6e30ab1

Please sign in to comment.