@@ -2,24 +2,30 @@ export const ERR_NO_CLIENTS = new Error("No clients provided in DgraphClient con
22export const ERR_FINISHED = new Error ( "Transaction has already been committed or discarded" ) ;
33export const ERR_ABORTED = new Error ( "Transaction has been aborted. Please retry" ) ;
44
5+ /**
6+ * CustomError is base class used for defining custom error classes.
7+ */
58export class CustomError extends Error {
69 public readonly name : string ;
710
811 constructor ( message ?: string ) {
912 super ( message ) ;
13+
14+ // tslint:disable no-any no-unsafe-any
1015 this . name = new . target . name ;
1116
1217 // fix the extended error prototype chain because typescript __extends implementation can't
13- const setPrototypeOf : Function = ( < any > Object ) . setPrototypeOf ; // tslint:disable-line no-any
14- setPrototypeOf
18+ const setPrototypeOf : Function = ( < any > Object ) . setPrototypeOf ;
19+ setPrototypeOf != null
1520 ? setPrototypeOf ( this , new . target . prototype )
16- : ( ( < any > this ) . __proto__ = new . target . prototype ) ; // tslint:disable-line no-any
21+ : ( ( < any > this ) . __proto__ = new . target . prototype ) ;
1722
1823 // try to remove contructor from stack trace
19- const captureStackTrace : Function = ( < any > Error ) . captureStackTrace ; // tslint:disable-line no-any
20- if ( captureStackTrace ) {
24+ const captureStackTrace : Function = ( < any > Error ) . captureStackTrace ;
25+ if ( captureStackTrace != null ) {
2126 captureStackTrace ( this , this . constructor ) ;
2227 }
28+ // tslint:enable no-any no-unsafe-any
2329 }
2430}
2531
@@ -28,6 +34,9 @@ export interface APIResultError {
2834 message : string ;
2935}
3036
37+ /**
38+ * APIError represents an error returned by Dgraph's HTTP server API.
39+ */
3140export class APIError extends CustomError {
3241 public readonly url : string ;
3342 public readonly errors : APIResultError [ ] ;
0 commit comments