add redactError and implement in apps
This commit is contained in:
parent
689732e2ff
commit
71fc8d5084
5 changed files with 28 additions and 7 deletions
5
.changeset/brave-rice-knock.md
Normal file
5
.changeset/brave-rice-knock.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@saleor/apps-shared": minor
|
||||
---
|
||||
|
||||
Added "redactError" helper. It should be used when logger.error is called to make safer error logs.
|
|
@ -9,7 +9,7 @@ import {
|
|||
ProductResponseSuccess,
|
||||
} from "../types";
|
||||
import { getCmsIdFromSaleorItem } from "./metadata";
|
||||
import { createLogger } from "@saleor/apps-shared";
|
||||
import { createLogger, redactError } from "@saleor/apps-shared";
|
||||
import { CMSProvider, cmsProviders } from "../providers";
|
||||
import { ProviderInstanceSchema, providersSchemaSet } from "../config";
|
||||
|
||||
|
@ -77,7 +77,7 @@ const executeCmsClientOperation = async ({
|
|||
} catch (error) {
|
||||
logger.error(
|
||||
{
|
||||
error: { message: (error as Error).message, stack: (error as Error).stack },
|
||||
error: redactError(error),
|
||||
},
|
||||
"Error deleting item"
|
||||
);
|
||||
|
@ -110,7 +110,7 @@ const executeCmsClientOperation = async ({
|
|||
});
|
||||
} catch (error) {
|
||||
logger.error("Error updating item", {
|
||||
error: { message: (error as Error).message, stack: (error as Error).stack },
|
||||
error: redactError(error),
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -145,7 +145,7 @@ const executeCmsClientOperation = async ({
|
|||
}
|
||||
} catch (error) {
|
||||
logger.error("Error creating item", {
|
||||
error: { message: (error as Error).message, stack: (error as Error).stack },
|
||||
error: redactError(error),
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -220,7 +220,7 @@ export const executeCmsClientBatchOperation = async ({
|
|||
} catch (error) {
|
||||
logger.error(
|
||||
{
|
||||
error: { message: (error as Error).message, stack: (error as Error).stack },
|
||||
error: redactError(error),
|
||||
},
|
||||
"Error creating batch items"
|
||||
);
|
||||
|
@ -268,7 +268,7 @@ export const executeCmsClientBatchOperation = async ({
|
|||
} catch (error) {
|
||||
logger.error(
|
||||
{
|
||||
error: { message: (error as Error).message, stack: (error as Error).stack },
|
||||
error: redactError(error),
|
||||
},
|
||||
"Error removing batch items"
|
||||
);
|
||||
|
|
|
@ -14,6 +14,7 @@ import { createClient } from "../../../lib/graphql";
|
|||
import { Client } from "urql";
|
||||
import { WebhookResponse } from "../../../modules/app/webhook-response";
|
||||
import { PROVIDER_ORDER_ID_KEY } from "../../../modules/avatax/order-fulfilled/avatax-order-fulfilled-payload-transformer";
|
||||
import { redactError } from "@saleor/apps-shared";
|
||||
|
||||
export const config = {
|
||||
api: {
|
||||
|
@ -98,7 +99,7 @@ export default orderCreatedAsyncWebhook.createHandler(async (req, res, ctx) => {
|
|||
return webhookResponse.success();
|
||||
} catch (error) {
|
||||
logger.error({
|
||||
error: { message: (error as Error).message, stack: (error as Error).stack },
|
||||
error: redactError(error),
|
||||
});
|
||||
return webhookResponse.error(new Error("Error while creating order in tax provider"));
|
||||
}
|
||||
|
|
|
@ -4,3 +4,4 @@ export * from "./src/no-ssr-wrapper";
|
|||
export * from "./src/use-dashboard-notification";
|
||||
export * from "./src/logger";
|
||||
export * from "./src/saleor-version-compatibility-validator";
|
||||
export * from "./src/redact-error";
|
||||
|
|
14
packages/shared/src/redact-error.ts
Normal file
14
packages/shared/src/redact-error.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
export const redactError = (err: unknown) => {
|
||||
if (err instanceof Error) {
|
||||
const { message, stack } = err;
|
||||
|
||||
return {
|
||||
message,
|
||||
stack,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
message: "Unknown error - redacted",
|
||||
};
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue