This repository has been archived by the owner on Apr 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding ES error cases to createError
- Loading branch information
Showing
3 changed files
with
34 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const _createError = require('http-errors'); | ||
const { errors } = require('@elastic/elasticsearch'); | ||
|
||
module.exports.createError = (...args) => { | ||
let status; | ||
let argToSend; | ||
let props = {}; | ||
for (let i = 0; i < args.length; i++) { | ||
let arg = args[i]; | ||
let type = typeof arg; | ||
if (type === 'object' && arg instanceof errors.ResponseError) { | ||
argToSend = _createError(arg.statusCode, `ElasticSearch Error:${arg.name}`, arg.meta); | ||
} else if (type === 'number' && i === 0) { | ||
status = arg; | ||
} else if (type === 'object' && !(arg instanceof Error)) { | ||
props = arg; | ||
} else { | ||
argToSend = arg; | ||
} | ||
} | ||
return _createError(status, argToSend, props); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters