Comparing version 4.2.0 to 4.3.0
22
async.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const custom_response_1 = require("./custom-response"); | ||
const error_1 = require("./error"); | ||
@@ -24,3 +25,3 @@ const types_1 = require("./types"); | ||
const isAsync = types_1.isAsyncMiddleware(middleware); | ||
const val = options.mapAsyncResultFn | ||
const mappedVal = options.mapAsyncResultFn | ||
? await options.mapAsyncResultFn(result, { | ||
@@ -32,2 +33,10 @@ isAsyncMiddleware: isAsync, | ||
: result; | ||
let val = mappedVal; | ||
let isRaw = false; | ||
let headers; | ||
if (mappedVal instanceof custom_response_1.CustomResponse) { | ||
val = mappedVal.value; | ||
isRaw = mappedVal.isRaw; | ||
headers = mappedVal.headers; | ||
} | ||
if (!isAsync) { | ||
@@ -60,3 +69,12 @@ // This middleware has `res` so we it will take care of the response | ||
} | ||
res.status(options.statusCode).json(val || {}); | ||
if (headers) { | ||
res.set(headers); | ||
} | ||
res.status(options.statusCode); | ||
if (isRaw) { | ||
res.send(val); | ||
} | ||
else { | ||
res.json(val || {}); | ||
} | ||
} | ||
@@ -63,0 +81,0 @@ catch (err) { |
{ | ||
"name": "async-app", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "An express wrapper for handling async middlewares, order middlewares, schema validator, and other stuff", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103511
63
1093