Last change
on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
841 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var getError = require('./get-error');
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * Where the given list is non-null and contains error instances then consolidate and throw
|
---|
7 | * @throws Error
|
---|
8 | * @param {string} resourcePath The path to the resource being processed
|
---|
9 | * @param {null|Array} candidates A possible Array with possible error elements
|
---|
10 | */
|
---|
11 | function throwErrors(resourcePath, candidates) {
|
---|
12 | var errors = !!candidates && candidates
|
---|
13 | .filter(testIsError)
|
---|
14 | .map(getMessage);
|
---|
15 |
|
---|
16 | var hasError = !!errors && errors.length;
|
---|
17 | if (hasError) {
|
---|
18 | throw getError(['For resource: ' + resourcePath].concat(errors).join('\n'));
|
---|
19 | }
|
---|
20 |
|
---|
21 | function testIsError(candidate) {
|
---|
22 | return !!candidate && (typeof candidate === 'object') && (candidate instanceof Error);
|
---|
23 | }
|
---|
24 |
|
---|
25 | function getMessage(error) {
|
---|
26 | return error.message;
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | module.exports = throwErrors; |
---|
Note:
See
TracBrowser
for help on using the repository browser.