File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,15 @@ This driver uses semantic versioning:
1616
1717## [ Unreleased]
1818
19+ ### Added
20+
21+ - Implemented ` toJSON ` methods for ` ArangoError ` and ` HttpError `
22+
23+ This prevents an error where ` JSON.stringify ` would reliably throw if passed
24+ an instance of either of these error types generated by arangojs. Note that
25+ you may still want to implement your own JSON representation logic as system
26+ errors (e.g. ` ECONNREFUSED ` ) are not wrapped by arangojs and thrown as-is.
27+
1928### Fixed
2029
2130- Stack traces are now improved for most errors when using ` precaptureStackTraces `
Original file line number Diff line number Diff line change @@ -155,6 +155,15 @@ export class ArangoError extends ExtendableError {
155155 get isArangoError ( ) : true {
156156 return true ;
157157 }
158+
159+ toJSON ( ) {
160+ return {
161+ error : true ,
162+ errorMessage : this . message ,
163+ errorNum : this . errorNum ,
164+ code : this . code ,
165+ } ;
166+ }
158167}
159168
160169/**
@@ -186,4 +195,11 @@ export class HttpError extends ExtendableError {
186195 if ( err [ key ] ) this [ key ] = err [ key ] ! ;
187196 }
188197 }
198+
199+ toJSON ( ) {
200+ return {
201+ error : true ,
202+ code : this . code ,
203+ } ;
204+ }
189205}
You can’t perform that action at this time.
0 commit comments