saleor-dashboard/src/utils/errors/webhooks.ts

29 lines
914 B
TypeScript
Raw Normal View History

import { WebhookErrorFragment } from "@saleor/fragments/types/WebhookErrorFragment";
2020-03-18 11:03:20 +00:00
import { commonMessages } from "@saleor/intl";
import { WebhookErrorCode } from "@saleor/types/globalTypes";
import { IntlShape } from "react-intl";
2020-03-18 11:03:20 +00:00
import commonErrorMessages from "./common";
function getWebhookErrorMessage(
err: Omit<WebhookErrorFragment, "__typename"> | undefined,
intl: IntlShape
): string {
if (err) {
switch (err.code) {
case WebhookErrorCode.GRAPHQL_ERROR:
return intl.formatMessage(commonErrorMessages.graphqlError);
case WebhookErrorCode.REQUIRED:
return intl.formatMessage(commonMessages.requiredField);
case WebhookErrorCode.INVALID:
return intl.formatMessage(commonErrorMessages.invalid);
default:
return intl.formatMessage(commonErrorMessages.unknownError);
}
}
return undefined;
}
export default getWebhookErrorMessage;