Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "abl-utils", | ||
"title": "ABL - utils", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "description": "description", |
@@ -21,2 +21,20 @@ "use strict"; | ||
export function processMongoError(error, user) { | ||
const key = error.message.match(/\$(\S+)/)[1]; | ||
return translate(`mongo.${key}`, user) || translate("mongo.E11000", user); | ||
} | ||
export function processStripeError(error, user) { | ||
switch (error.type) { | ||
case "StripeCardError": | ||
case "StripeInvalidRequestError": | ||
return error.message; | ||
case "StripeAPIError": | ||
case "StripeConnectionError": | ||
case "StripeAuthenticationError": | ||
default: | ||
return translate("api.stripe-bad-request", user); | ||
} | ||
} | ||
export function sendError(error, request, response, next) { | ||
@@ -34,8 +52,13 @@ const log = debug("utils:response"); | ||
if (error.name === "MongoError" && error.code === 11000) { | ||
const key = error.message.match(/\$(\S+)/)[1]; | ||
return send({ | ||
status: 400, | ||
message: translate(`mongo.${key}`, request.user) || translate("mongo.E11000", request.user) | ||
message: processMongoError(error, request.user) | ||
}); | ||
} | ||
if (error.type && error.type.startsWith("Stripe")) { | ||
return send({ | ||
status: 400, | ||
message: processStripeError(error, request.user) | ||
}); | ||
} | ||
if (!error.status) { | ||
@@ -80,17 +103,5 @@ if (process.env.NODE_ENV === "production") { | ||
.then(response.json.bind(response)) | ||
.catch(error => { | ||
switch (error.type) { | ||
case "StripeCardError": | ||
case "StripeInvalidRequestError": | ||
Object.assign(error, {status: 400}); | ||
return sendError(error, request, response); | ||
case "StripeAPIError": | ||
case "StripeConnectionError": | ||
case "StripeAuthenticationError": | ||
default: | ||
return sendError(process.env.NODE_ENV === "production" ? makeError("api.stripe-bad-request", request.user, 400) : error, request, response); | ||
} | ||
}) | ||
.catch(error => sendError(error, request, response)) | ||
.done(); | ||
}; | ||
} |
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
8027
175
2