screwdriver-api 7.0.239 → 7.0.240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "7.0.239",
3
+ "version": "7.0.240",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -433,18 +433,38 @@ async function startEvents(eventConfigs, eventFactory) {
433
433
  })
434
434
  );
435
435
 
436
+ const errors = [];
437
+
436
438
  results.forEach((result, i) => {
437
439
  if (result.status === 'fulfilled') {
438
440
  if (result.value) events.push(result.value);
439
441
  } else {
440
442
  errorCount += 1;
443
+ errors.push(result.reason);
441
444
  logger.error(`pipeline:${eventConfigs[i].pipelineId} error in starting event`, result.reason);
442
445
  }
443
446
  });
444
447
 
445
- if (errorCount && errorCount === eventsCount) {
448
+ if (errorCount > 0 && errorCount === eventsCount) {
446
449
  // preserve current behavior of returning 500 on error
447
- throw new Error('Failed to start any events');
450
+ const errorMessages = new Set();
451
+ let statusCode = 500;
452
+
453
+ errors.forEach(err => {
454
+ errorMessages.add(`"${err.message}"`);
455
+ if (err.statusCode !== undefined) {
456
+ statusCode = err.statusCode;
457
+ }
458
+ });
459
+
460
+ const errorMessage = [...errorMessages].join(', ');
461
+ const error =
462
+ errorCount === 1
463
+ ? new Error(`Failed to start a event caused by ${errorMessage}`)
464
+ : new Error(`Failed to start some events caused by ${errorMessage}`);
465
+
466
+ error.statusCode = statusCode;
467
+ throw error;
448
468
  }
449
469
 
450
470
  return events;