2022-03-09 08:56:55 +00:00
|
|
|
import { AppErrorCode, AppErrorFragment } from "@saleor/graphql";
|
2020-07-22 10:54:15 +00:00
|
|
|
import { defineMessages, IntlShape } from "react-intl";
|
|
|
|
|
2021-09-14 13:57:02 +00:00
|
|
|
import { getCommonFormFieldErrorMessage } from "./common";
|
2020-07-22 10:54:15 +00:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
invalidManifestFormat: {
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "pC6/1z",
|
2022-06-21 09:36:55 +00:00
|
|
|
defaultMessage: "Invalid manifest format",
|
2020-07-22 10:54:15 +00:00
|
|
|
},
|
|
|
|
invalidPermission: {
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "D2qihU",
|
2022-06-21 09:36:55 +00:00
|
|
|
defaultMessage: "Permission is invalid",
|
2020-07-22 10:54:15 +00:00
|
|
|
},
|
|
|
|
invalidStatus: {
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "v3WWK+",
|
2022-06-21 09:36:55 +00:00
|
|
|
defaultMessage: "Status is invalid",
|
2020-07-22 10:54:15 +00:00
|
|
|
},
|
|
|
|
invalidUrlFormat: {
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "g/BrOt",
|
2022-06-21 09:36:55 +00:00
|
|
|
defaultMessage: "Url has invalid format",
|
2020-07-22 10:54:15 +00:00
|
|
|
},
|
|
|
|
outOfScopeApp: {
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "C4hCsD",
|
2022-06-21 09:36:55 +00:00
|
|
|
defaultMessage: "App is out of your permissions scope",
|
2020-07-22 10:54:15 +00:00
|
|
|
},
|
|
|
|
outOfScopeGroup: {
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "1n1tOR",
|
2022-06-21 09:36:55 +00:00
|
|
|
defaultMessage: "Group is out of your permission scope",
|
2020-07-22 10:54:15 +00:00
|
|
|
},
|
|
|
|
outOfScopePermission: {
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "4prRLv",
|
2022-06-21 09:36:55 +00:00
|
|
|
defaultMessage: "Permission is out of your scope",
|
2020-07-22 10:54:15 +00:00
|
|
|
},
|
|
|
|
unique: {
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "TDhHMi",
|
2022-06-21 09:36:55 +00:00
|
|
|
defaultMessage: "This needs to be unique",
|
|
|
|
},
|
2020-07-22 10:54:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function getAppErrorMessage(err: AppErrorFragment, intl: IntlShape): string {
|
|
|
|
if (err) {
|
|
|
|
switch (err.code) {
|
|
|
|
case AppErrorCode.INVALID_MANIFEST_FORMAT:
|
|
|
|
return intl.formatMessage(messages.invalidManifestFormat);
|
|
|
|
case AppErrorCode.OUT_OF_SCOPE_APP:
|
|
|
|
return intl.formatMessage(messages.outOfScopeApp);
|
|
|
|
case AppErrorCode.OUT_OF_SCOPE_PERMISSION:
|
|
|
|
return intl.formatMessage(messages.outOfScopePermission);
|
|
|
|
case AppErrorCode.INVALID_PERMISSION:
|
|
|
|
return intl.formatMessage(messages.invalidPermission);
|
|
|
|
case AppErrorCode.INVALID_STATUS:
|
|
|
|
return intl.formatMessage(messages.invalidStatus);
|
|
|
|
case AppErrorCode.INVALID_URL_FORMAT:
|
|
|
|
return intl.formatMessage(messages.invalidUrlFormat);
|
|
|
|
case AppErrorCode.UNIQUE:
|
|
|
|
return intl.formatMessage(messages.unique);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-14 13:57:02 +00:00
|
|
|
return getCommonFormFieldErrorMessage(err, intl);
|
2020-07-22 10:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default getAppErrorMessage;
|