@@ -4,11 +4,18 @@ export class LibraryError extends Error {
44 super ( message , options ) ;
55 this . name = "LibraryError" ;
66 }
7+ get detail ( ) {
8+ return {
9+ type : `https://docs.applura.com/client/v2/errors#${ this . name } ` ,
10+ title : this . name ,
11+ detail : this . message ,
12+ } ;
13+ }
714}
815
916// Raised when the implementation of this library has caused an error. For example, when a known edge case has not been
1017// handled.
11- export class ImplementationError extends Error {
18+ export class ImplementationError extends LibraryError {
1219 constructor ( message , options ) {
1320 super ( message , options ) ;
1421 this . name = "ImplementationError" ;
@@ -23,22 +30,34 @@ export class UsageError extends LibraryError {
2330 }
2431}
2532
26- // Raised when an HTTP request causes an HTTP client error, i.e. for HTTP status codes >=300 and <=399 .
27- export class RequestError extends LibraryError {
28- constructor ( message , { doc , response, ...options } ) {
33+ // Raised when an HTTP response is in error, i.e. for HTTP status codes >=400 .
34+ export class HTTPError extends LibraryError {
35+ constructor ( message , { response, ...options } ) {
2936 super ( message , options ) ;
3037 this . name = "RequestError" ;
31- Object . defineProperty ( this , "doc" , { value : doc } ) ;
3238 Object . defineProperty ( this , "response" , { value : response } ) ;
3339 }
40+ get detail ( ) {
41+ return {
42+ ...super . detail ,
43+ status : this . response . status ,
44+ } ;
45+ }
46+ }
47+
48+ // Raised when an HTTP request causes an HTTP client error, i.e. for HTTP status codes >=400 and <=499.
49+ export class RequestError extends HTTPError {
50+ constructor ( message , options ) {
51+ super ( message , options ) ;
52+ this . name = "RequestError" ;
53+ }
3454}
3555
3656// Raised when an HTTP response causes an error.
37- export class ResponseError extends LibraryError {
38- constructor ( message , { doc , response , ... options } ) {
39- super ( message , { ... options , doc : { value : doc } } ) ;
57+ export class ResponseError extends HTTPError {
58+ constructor ( message , options ) {
59+ super ( message , options ) ;
4060 this . name = "ResponseError" ;
41- Object . defineProperty ( this , "response" , { value : response } ) ;
4261 }
4362}
4463
0 commit comments