UNPKG

@vtex/api

Version:
24 lines (23 loc) 902 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.notFoundFallbackMiddleware = exports.acceptNotFoundMiddleware = void 0; const addNotFound = (validateStatus) => (status) => validateStatus(status) || status === 404; function nullIfNotFound(config) { return config && config.nullIfNotFound; } const acceptNotFoundMiddleware = async (ctx, next) => { const { config } = ctx; if (nullIfNotFound(config)) { ctx.config.validateStatus = addNotFound(config.validateStatus); } await next(); }; exports.acceptNotFoundMiddleware = acceptNotFoundMiddleware; const notFoundFallbackMiddleware = async (ctx, next) => { await next(); const { config } = ctx; if (nullIfNotFound(config) && ctx.response && ctx.response.status === 404) { ctx.response.data = null; } }; exports.notFoundFallbackMiddleware = notFoundFallbackMiddleware;