@betit/orion-node-sdk
Advanced tools
Comparing version
@@ -11,5 +11,9 @@ import { Logger, Message as MessageInterface } from '../types/interfaces'; | ||
private _stack; | ||
private _error; | ||
private _args; | ||
constructor(_client: Logger, _host: string, _message: string); | ||
setLevel(level: number): this; | ||
/** | ||
* @deprecated | ||
*/ | ||
setLOC(err: Error): this; | ||
@@ -19,3 +23,4 @@ setId(id: string): this; | ||
setMap(params: object): this; | ||
setError(err: Error): this; | ||
send(): void; | ||
} |
@@ -14,2 +14,5 @@ "use strict"; | ||
} | ||
/** | ||
* @deprecated | ||
*/ | ||
setLOC(err) { | ||
@@ -35,2 +38,12 @@ const LOC = index_1.getLineFromError(err); | ||
} | ||
setError(err) { | ||
const parsed = index_1.parseError(err); | ||
const error = { | ||
message: parsed.message, | ||
stack: parsed.stack, | ||
code: parsed.code, | ||
}; | ||
this._error = JSON.stringify(error); | ||
return this; | ||
} | ||
send() { | ||
@@ -48,8 +61,5 @@ let m = { | ||
} | ||
if (this._loc !== undefined) { | ||
m.loc = this._loc; | ||
if (this._error !== undefined) { | ||
m.error = this._error; | ||
} | ||
if (this._stack !== undefined) { | ||
m.stack = this._stack; | ||
} | ||
if (this._id !== undefined) { | ||
@@ -56,0 +66,0 @@ m['x-trace-id'] = this._id; |
@@ -39,2 +39,3 @@ import { Request } from '../request/request'; | ||
setLOC(err: Error): this; | ||
setError(err: Error): this; | ||
send(): any; | ||
@@ -41,0 +42,0 @@ } |
@@ -17,3 +17,4 @@ import { OrionError } from '../error/error'; | ||
}; | ||
export declare function parseError(err: Error): any; | ||
export declare function StringifyError(e: Error | OrionError): string; | ||
export declare function sleep(ms: any): Promise<void>; |
@@ -78,2 +78,26 @@ "use strict"; | ||
exports.getLineFromError = getLineFromError; | ||
function parseError(err) { | ||
// Maximum error stack size | ||
const STACK_SIZE = 5; | ||
const properties = {}; | ||
properties.isError = true; | ||
if (!err || !err.message || !err.stack) { | ||
properties.isError = false; | ||
err = new Error(JSON.stringify(err)); | ||
} | ||
Object.getOwnPropertyNames(err).forEach(function (key) { | ||
properties[key] = err[key]; | ||
}, err); | ||
// Example: https://nodejs.org/api/errors.html#errors_error_stack | ||
if (properties.stack) { | ||
const lines = properties.stack.split('\n'); | ||
const stack = []; | ||
for (let i = 1; i < lines.length && i < STACK_SIZE; i++) { | ||
stack.push(lines[i].replace(' at ', '')); | ||
} | ||
properties.stack = stack.join(''); | ||
} | ||
return properties; | ||
} | ||
exports.parseError = parseError; | ||
function StringifyError(e) { | ||
@@ -80,0 +104,0 @@ if (e instanceof error_1.OrionError) { |
{ | ||
"name": "@betit/orion-node-sdk", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "SDK for orion", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1807842
3.28%143
4.38%3303
1.26%4
33.33%