2020-11-23 13:04:24 +00:00
|
|
|
import { AppErrorFragment } from "@saleor/fragments/types/AppErrorFragment";
|
2020-07-22 10:54:15 +00:00
|
|
|
import { AppErrorCode } from "@saleor/types/globalTypes";
|
|
|
|
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: {
|
|
|
|
defaultMessage: "Invalid manifest format"
|
|
|
|
},
|
|
|
|
invalidPermission: {
|
|
|
|
defaultMessage: "Permission is invalid"
|
|
|
|
},
|
|
|
|
invalidStatus: {
|
|
|
|
defaultMessage: "Status is invalid"
|
|
|
|
},
|
|
|
|
invalidUrlFormat: {
|
|
|
|
defaultMessage: "Url has invalid format"
|
|
|
|
},
|
|
|
|
outOfScopeApp: {
|
|
|
|
defaultMessage: "App is out of your permissions scope"
|
|
|
|
},
|
|
|
|
outOfScopeGroup: {
|
|
|
|
defaultMessage: "Group is out of your permission scope"
|
|
|
|
},
|
|
|
|
outOfScopePermission: {
|
|
|
|
defaultMessage: "Permission is out of your scope"
|
|
|
|
},
|
|
|
|
unique: {
|
|
|
|
defaultMessage: "This needs to be unique"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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;
|