2020-07-07 10:14:12 +00:00
|
|
|
import { WebhookErrorFragment } from "@saleor/fragments/types/WebhookErrorFragment";
|
2020-03-18 11:03:20 +00:00
|
|
|
import { commonMessages } from "@saleor/intl";
|
2020-05-14 09:30:32 +00:00
|
|
|
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;
|