aboutsummaryrefslogtreecommitdiffstats
path: root/lib/middleware.js
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2018-05-04 12:26:17 -0400
committerAlex Shatov <alexs@att.com>2018-05-04 12:26:17 -0400
commita46339420faefc49cb48adf2989a0884ff961278 (patch)
tree3862914b2996f355982085784bdea3f77ba0fd85 /lib/middleware.js
parentf8cab3eebdcee288332e16bda5bd6b2fa17e02ac (diff)
fixed 500 "value" argument is out of bounds
- convert the EOL to linux "\n" in the blueprint before zipping and sending to cloudify to avoid crashing when the blueprint is windows "\r\n" or mac "\r" based - on catching the exception - log the stack - added logger.info that replaced the logger.debug in a variety of places - external version 2.1.2, internal version 4.4.2 - unit test code coverage Statements : 84.26% ( 942/1118 ) Branches : 64.14% ( 322/502 ) Functions : 81.68% ( 156/191 ) Lines : 84.32% ( 930/1103 ) Change-Id: I9f5f28ddd5d143ca4903316c9199df7d27682143 Signed-off-by: Alex Shatov <alexs@att.com> Issue-ID: DCAEGEN2-487
Diffstat (limited to 'lib/middleware.js')
-rw-r--r--lib/middleware.js29
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/middleware.js b/lib/middleware.js
index 183cf77..ee39863 100644
--- a/lib/middleware.js
+++ b/lib/middleware.js
@@ -1,16 +1,16 @@
/*
-Copyright(c) 2017 AT&T Intellectual Property. All rights reserved.
+Copyright(c) 2017-2018 AT&T Intellectual Property. All rights reserved.
-Licensed under the Apache License, Version 2.0 (the "License");
+Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
-Unless required by applicable law or agreed to in writing,
+Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-CONDITIONS OF ANY KIND, either express or implied.
+CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
*/
@@ -32,12 +32,19 @@ exports.assignId = function(req, res, next) {
/* Error handler -- send error with JSON body */
exports.handleErrors = function(err, req, res, next) {
- var status = err.status || 500;
- var msg = err.message || err.body || 'unknown error'
- res.status(status).type('application/json').send({status: status, message: msg });
- log.audit(req, status, msg);
+ const response = {
+ status : err.status || 500,
+ message : err.message || err.body || 'unknown error'
+ };
+ if (err.stack) {
+ response.stack = err.stack.split("\n");
+ }
+
+ res.status(response.status).type('application/json').send(response);
+ log.audit(req, response.status, JSON.stringify(response));
- if (status >= 500) {
+ if (response.status >= 500) {
+ err.message = response.message + (err.stack && " " + response.stack.join(', '));
log.error(err, req);
}
};
@@ -55,7 +62,7 @@ exports.checkType = function(type){
var err = new Error ('Content-Type must be \'' + type +'\'');
err.status = 415;
next (err);
- }
+ }
};
};
@@ -70,7 +77,7 @@ exports.checkProps = function(props) {
}
else {
next();
- }
+ }
};
};