help-me-respond
Advanced tools
Comparing version 1.0.6 to 1.1.0
54
index.js
@@ -43,4 +43,6 @@ var config = require("config") | ||
502, | ||
res, | ||
{ statusCode: code, message: body}, | ||
res, { | ||
statusCode: code, | ||
message: body | ||
}, | ||
headers | ||
@@ -61,2 +63,7 @@ ); | ||
// if there is no code in the message, its probably error | ||
code = code ? code : 400; | ||
// empty message is ok | ||
msg = msg ? msg : ''; | ||
res = res.status(code); | ||
@@ -67,3 +74,5 @@ if (headers && headers !== undefined) { | ||
} else { | ||
var headers = {'content-type': 'application/json'}; | ||
var headers = { | ||
'content-type': 'application/json' | ||
}; | ||
res = res.header(headers); | ||
@@ -76,12 +85,12 @@ } | ||
if(code == 502 && msg.message && msg.statusCode && msg.message instanceof Error) { | ||
if (code == 502 && msg.message && msg.statusCode && msg.message instanceof Error) { | ||
msg.message = msg.message.message.toString() | ||
} | ||
if(tools.isJsonString(msg)) { | ||
if (tools.isJsonString(msg)) { | ||
var jsonObj = JSON.parse(msg) | ||
if(jsonObj.msg) { | ||
if (jsonObj.msg) { | ||
msg = jsonObj.msg | ||
} | ||
if(jsonObj.args) { | ||
if (jsonObj.args) { | ||
args = jsonObj.args | ||
@@ -92,8 +101,12 @@ } | ||
// friendly messages for users | ||
if(checkFriendly(msg)) { | ||
msg = {friendlyMessage : i18n.__(msg, args)} | ||
} else if(msg && msg instanceof Object){ | ||
msg = {data: msg} | ||
} else if(code == 502) { | ||
if(checkFriendly(msg.message)){ | ||
if (checkFriendly(msg)) { | ||
msg = { | ||
friendlyMessage: i18n.__(msg, args) | ||
} | ||
} else if (msg && msg instanceof Object) { | ||
msg = { | ||
data: msg | ||
} | ||
} else if (code == 502) { | ||
if (checkFriendly(msg.message)) { | ||
msg.friendlyMessage = i18n.__(msg.message, args) | ||
@@ -105,10 +118,15 @@ delete msg.message | ||
} else { | ||
msg = {message: i18n.__(msg, args)} | ||
msg = { | ||
message: i18n.__(msg, args) | ||
} | ||
} | ||
if(code >= 400) { | ||
if(!msg) { | ||
if (code >= 400) { | ||
if (!msg) { | ||
msg = '' | ||
} | ||
msg = {code: code, error: msg} | ||
msg = { | ||
code: code, | ||
error: msg | ||
} | ||
} | ||
@@ -120,3 +138,3 @@ | ||
function checkFriendly(msg) { | ||
if(config && config.friendlyMessages){ | ||
if (config && config.friendlyMessages) { | ||
return config.friendlyMessages.indexOf(msg) !== -1 | ||
@@ -123,0 +141,0 @@ } |
{ | ||
"name": "help-me-respond", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"description": "Simple nodejs response helper", | ||
@@ -10,16 +10,16 @@ "main": "index.js", | ||
"keywords": [ | ||
"node response", | ||
"nodejs response", | ||
"response helper", | ||
"symphonyno9", | ||
"express response" | ||
"node response", | ||
"nodejs response", | ||
"response helper", | ||
"symphonyno9", | ||
"express response" | ||
], | ||
"author": "Daria Mikhailova <drmikhailova@gmail.com>", | ||
"repository" :{ | ||
"type" : "git", | ||
"url" : "https://github.com/Symphony9/help-me-respond" | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Symphony9/help-me-respond" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Symphony9/help-me-respond/issues" | ||
}, | ||
"url": "https://github.com/Symphony9/help-me-respond/issues" | ||
}, | ||
"license": "ISC", | ||
@@ -26,0 +26,0 @@ "dependencies": { |
## Help me respond | ||
This is a simple response helper which should make you life a bit easier. It supports localization and friendly messages for users. | ||
This is a simple response helper which should make you life a bit easier. It supports localization and friendly messages for users. | ||
Help-me-respond preconfigures HTTP responses for you by setting up the status code, processing the message and setting headers. You only need to call one of the API functions and pass the message in a form of a string or an object to it. | ||
@@ -5,0 +6,0 @@ ## Prerequisites for usage |
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
7536
145
136