Skip to content

Commit

Permalink
Fix improper error handling (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
crd1985 authored and jesuslinares committed Jan 24, 2019
1 parent 69d7e8e commit 223e54e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.

## [v3.8.1]

### Fixed
- Fixed improper error handling ([#296](https://github.com/wazuh/wazuh-api/pull/296))

## [v3.8.0]

### Added
Expand Down
7 changes: 2 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,11 @@ app.use (function (err, req, res, next){
else if ('status' in err && err.status == 400){
var msg = "";
if ('body' in err)
msg = "Body: " + err.body;
msg = "Body is not correct.";
res_h.bad_request(req, res, "614", msg);
}
else if (err == "PayloadTooLargeError: request entity too large"){
var msg = "";
if ('body' in err)
msg = "Body: " + err.body;
res_h.bad_request(req, res, "701", msg);
res_h.bad_request(req, res, "701");
}
else{
logger.log("Internal Error");
Expand Down
12 changes: 10 additions & 2 deletions helpers/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,16 @@ exports.exec = function(cmd, args, stdin, callback) {
if ( json_cmd.hasOwnProperty('data') )
json_result.data = json_cmd.data;

if ( json_cmd.hasOwnProperty('message') )
json_result.message = json_cmd.message;
if ( json_cmd.hasOwnProperty('message') ){
logger.error(json_cmd.message);
if ( json_result.error === 1000)
json_result.message = "Internal error";
else{
if (typeof json_cmd.message === 'string')
json_result.message = json_cmd.message.split(":", 1)[0];
}

}
}
else{
json_result = {"error": 1, "message": errors.description(1) + ". Wrong keys"}; // JSON Wrong keys
Expand Down

0 comments on commit 223e54e

Please sign in to comment.