UNPKG

@appello/services

Version:

Services package with api / graphql

39 lines (38 loc) 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getGqlErrors = getGqlErrors; exports.getGqlError = getGqlError; exports.getGqlErrorCode = getGqlErrorCode; exports.isGqlUnauthorizedError = isGqlUnauthorizedError; exports.isGqlUnknownError = isGqlUnknownError; exports.isGqlBusinessError = isGqlBusinessError; exports.getNonFieldGqlError = getNonFieldGqlError; const consts_1 = require("../../consts"); function getGqlErrors(e) { return e.graphQLErrors; } function getGqlError(gqlErrors) { var _a; return (_a = gqlErrors === null || gqlErrors === void 0 ? void 0 : gqlErrors[0]) === null || _a === void 0 ? void 0 : _a.extensions; } function getGqlErrorCode(gqlErrors) { var _a; return (_a = getGqlError(gqlErrors)) === null || _a === void 0 ? void 0 : _a.code; } function isGqlUnauthorizedError(gqlErrors) { return getGqlErrorCode(gqlErrors) === consts_1.GqlErrorCodeEnum.TOKEN_EXPIRED; } function isGqlUnknownError(gqlErrors) { return getGqlErrorCode(gqlErrors) === consts_1.GqlErrorCodeEnum.UNKNOWN_ERROR; } function isGqlBusinessError(gqlErrors) { return [consts_1.GqlErrorCodeEnum.UNPROCESSABLE_ENTITY, consts_1.GqlErrorCodeEnum.RESOURCE_NOT_FOUND].includes(getGqlErrorCode(gqlErrors)); } function getNonFieldGqlError(e) { const graphQLErrors = getGqlErrors(e); const errors = getGqlError(graphQLErrors); if ((errors === null || errors === void 0 ? void 0 : errors.explain) && 'non_field' in errors.explain) { return errors.explain.non_field; } return null; }