File tree Expand file tree Collapse file tree
packages/javascript-api/src/lib/services/api-base Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -397,6 +397,30 @@ describe('ApiBase', () => {
397397 } ,
398398 ) ;
399399 } ) ;
400+
401+ it ( 'should handle error with complex error in "errors" property' , ( done ) => {
402+ Qminder . setKey ( API_KEY ) ;
403+
404+ const response : any = {
405+ ok : false ,
406+ statusCode : 409 ,
407+ errors : { email : 'Email already in use' } ,
408+ } ;
409+
410+ fetchSpy . mockReturnValue ( new MockResponse ( response ) ) ;
411+
412+ Qminder . ApiBase . request ( 'TEST' ) . then (
413+ ( ) => done ( new Error ( 'Should have errored' ) ) ,
414+ ( error : ComplexError ) => {
415+ expect ( error . error ) . toEqual ( { email : 'Email already in use' } ) ;
416+ expect ( error . message ) . toEqual (
417+ 'Error occurred! Check error property for more information!' ,
418+ ) ;
419+ expect ( error instanceof ComplexError ) . toBeTruthy ( ) ;
420+ done ( ) ;
421+ } ,
422+ ) ;
423+ } ) ;
400424 } ) ;
401425
402426 describe ( 'queryGraph()' , ( ) => {
Original file line number Diff line number Diff line change @@ -174,6 +174,9 @@ export class ApiBase {
174174 if ( Object . prototype . hasOwnProperty . call ( response , 'error' ) ) {
175175 return new ComplexError ( response . error ) ;
176176 }
177+ if ( Object . prototype . hasOwnProperty . call ( response , 'errors' ) ) {
178+ return new ComplexError ( response . errors ) ;
179+ }
177180
178181 return new UnknownError ( ) ;
179182 }
You can’t perform that action at this time.
0 commit comments