@@ -295,6 +295,54 @@ describe("utils", function () {
295295 }
296296 } ) ;
297297
298+ it ( "should return an error based on single errors (array) property on the response body and description if present" , function ( done ) {
299+ const TEST_ERROR_1 = "First error message used for testing." ;
300+ const DESCRIPTION_1 = 'Additional description.' ;
301+ const testError = null ;
302+ let error1 = new Error ( TEST_ERROR_1 ) ;
303+ error1 . description = DESCRIPTION_1 ;
304+ const testBody = { "errors" : [ error1 ] } ;
305+ const testResponse = null ;
306+ const testRequestOptions = null ;
307+ let error ;
308+ try {
309+ const error = utils . getError ( testError , testBody , testResponse , testRequestOptions ) ;
310+ expect ( error . message ) . to . contain ( TEST_ERROR_1 ) ;
311+ expect ( error . message ) . to . contain ( DESCRIPTION_1 ) ;
312+ } catch ( err ) {
313+ error = err ;
314+ } finally {
315+ done ( error ) ;
316+ }
317+ } ) ;
318+
319+ it ( "should return an error based on the errors (array) property on the response body and description if present" , function ( done ) {
320+ const TEST_ERROR_1 = "First error message used for testing." ;
321+ const TEST_ERROR_2 = "Second error message used for testing." ;
322+ const DESCRIPTION_1 = 'Additional description.' ;
323+ const DESCRIPTION_2 = '2nd additional description.' ;
324+ const testError = null ;
325+ let error1 = new Error ( TEST_ERROR_1 ) ;
326+ error1 . description = DESCRIPTION_1 ;
327+ let error2 = new Error ( TEST_ERROR_2 ) ;
328+ error2 . description = DESCRIPTION_2 ;
329+ const testBody = { "errors" : [ error1 , error2 ] } ;
330+ const testResponse = null ;
331+ const testRequestOptions = null ;
332+ let error ;
333+ try {
334+ const error = utils . getError ( testError , testBody , testResponse , testRequestOptions ) ;
335+ expect ( error . message ) . to . contain ( TEST_ERROR_1 ) ;
336+ expect ( error . message ) . to . contain ( TEST_ERROR_2 ) ;
337+ expect ( error . message ) . to . contain ( DESCRIPTION_1 ) ;
338+ expect ( error . message ) . to . contain ( DESCRIPTION_2 ) ;
339+ } catch ( err ) {
340+ error = err ;
341+ } finally {
342+ done ( error ) ;
343+ }
344+ } ) ;
345+
298346 it ( "should return an error based on the errors (non-array Error) property on the response body" , function ( done ) {
299347 const TEST_ERROR_1 = "First error message used for testing." ;
300348 const testError = null ;
0 commit comments