Skip to content

Commit

Permalink
Add support for TransactionAlreadyCancelled to AvaTax (#1596)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofzuraw authored Sep 30, 2024
1 parent 3896e77 commit 186bad7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-trains-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-avatax": patch
---

Added TransactionAlreadyCancelled support for AvaTax app while canceling Saleor order.
9 changes: 9 additions & 0 deletions apps/avatax/src/modules/avatax/avatax-errors-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
AvataxInvalidAddressError,
AvataxInvalidCredentialsError,
AvataxStringLengthError,
AvataxTransactionAlreadyCancelledError,
} from "../taxes/tax-error";
import { assertUnreachableWithoutThrow } from "../utils/assert-unreachable";
import { normalizeAvaTaxError } from "./avatax-error-normalizer";
Expand All @@ -23,6 +24,7 @@ export class AvataxErrorsParser {
"AuthenticationException",
"StringLengthError",
"EntityNotFoundError",
"TransactionAlreadyCancelled",
]),
details: z.array(
z.object({
Expand Down Expand Up @@ -74,6 +76,13 @@ export class AvataxErrorsParser {
},
});
}
case "TransactionAlreadyCancelled": {
return new AvataxTransactionAlreadyCancelledError(parsedError.data.code, {
props: {
description: parsedError.data.details[0].description,
},
});
}
default: {
assertUnreachableWithoutThrow(parsedError.data.code);
return normalizeAvaTaxError(err);
Expand Down
9 changes: 9 additions & 0 deletions apps/avatax/src/modules/taxes/tax-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ export const AvataxEntityNotFoundError = ExpectedError.subclass("AvataxEntityNot
description: "",
},
});

export const AvataxTransactionAlreadyCancelledError = ExpectedError.subclass(
"AvataxTransactionAlreadyCancelledError",
{
props: {
description: "",
},
},
);
11 changes: 11 additions & 0 deletions apps/avatax/src/pages/api/webhooks/order-cancelled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { captureException } from "@sentry/nextjs";
import { AvataxOrderCancelledAdapter } from "@/modules/avatax/order-cancelled/avatax-order-cancelled-adapter";
import { ClientLogStoreRequest } from "@/modules/client-logs/client-log";
import { LogWriterFactory } from "@/modules/client-logs/log-writer-factory";
import { AvataxTransactionAlreadyCancelledError } from "@/modules/taxes/tax-error";

import { AppConfigExtractor } from "../../../lib/app-config-extractor";
import { AppConfigurationLogger } from "../../../lib/app-configuration-logger";
Expand Down Expand Up @@ -228,6 +229,16 @@ export default wrapWithLoggerContext(
});
}

if (e instanceof AvataxTransactionAlreadyCancelledError) {
logger.warn("Transaction was already cancelled in AvaTax. Responding 200", {
error: e,
});

return res.status(200).send({
message: "Transaction was already cancelled in AvaTax",
});
}

ClientLogStoreRequest.create({
level: "error",
message: "Failed to void order. AvaTax returned error.",
Expand Down

0 comments on commit 186bad7

Please sign in to comment.