UNPKG

@apite/magento2-utility

Version:

Shopgate WebCheckout utility for Magento 2 extensions

44 lines (39 loc) 1.11 kB
'use strict' const get = require('lodash.get') const { GraphQLError, UnknownError } = require('../lib/errorList') const { decorateError } = require('./logDecorator')() /** * @param {AxiosError<{message: string}>|Error} error * @param {ApiteM2Utility.PipelineContext} context * @throws {UnknownError} */ const throwOnApiError = (error, context) => { switch (get(error, 'response.status') || 0) { case 401: case 400: case 403: case 404: case 412: case 429: case 500: default: context.log.error(decorateError(get(error, 'response') || error), 'rest-unmapped-error') throw new UnknownError() } } /** * @param {GraphQLError|AxiosError<{message: string}>} error * @param {ApiteM2Utility.PipelineContext} context * @throws {UnknownError|ProductNotFoundError} */ const throwOnGraphQLError = (error, context) => { if (!(error instanceof GraphQLError)) { throwOnApiError(error, context) } context.log.error(error.getFormattedError(), 'gql-unmapped-error') throw new UnknownError() } module.exports = { throwOnApiError, throwOnGraphQLError }