2020-12-03 20:50:00 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2018-2020 Balena Ltd.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2018-10-16 10:25:37 +00:00
|
|
|
import * as _ from 'lodash';
|
2020-12-03 20:50:00 +00:00
|
|
|
|
|
|
|
import { ExpectedError } from '../../errors';
|
2018-10-16 10:25:37 +00:00
|
|
|
|
|
|
|
export interface BuildFailure {
|
|
|
|
error: Error;
|
|
|
|
serviceName: string;
|
|
|
|
}
|
|
|
|
|
2020-12-03 20:50:00 +00:00
|
|
|
export class BuildError extends ExpectedError {
|
2018-10-16 10:25:37 +00:00
|
|
|
private failures: BuildFailure[];
|
|
|
|
|
|
|
|
public constructor(failures: BuildFailure[]) {
|
|
|
|
super('Build error');
|
|
|
|
|
|
|
|
this.failures = failures;
|
|
|
|
}
|
|
|
|
|
|
|
|
public toString(): string {
|
|
|
|
let str = 'Some services failed to build:\n';
|
2020-06-15 22:53:07 +00:00
|
|
|
_.each(this.failures, (failure) => {
|
2018-10-16 10:25:37 +00:00
|
|
|
str += `\t${failure.serviceName}: ${failure.error.message}\n`;
|
|
|
|
});
|
|
|
|
return str;
|
|
|
|
}
|
2019-04-19 15:17:06 +00:00
|
|
|
|
|
|
|
public getServiceError(serviceName: string): string {
|
2020-06-15 22:53:07 +00:00
|
|
|
const failure = _.find(this.failures, (f) => f.serviceName === serviceName);
|
2019-04-19 15:17:06 +00:00
|
|
|
if (failure == null) {
|
|
|
|
return 'Unknown build failure';
|
|
|
|
}
|
|
|
|
|
|
|
|
return failure.error.message;
|
|
|
|
}
|
2018-10-16 10:25:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 20:50:00 +00:00
|
|
|
export class DeviceAPIError extends ExpectedError {}
|
2018-10-16 10:25:37 +00:00
|
|
|
|
|
|
|
export class BadRequestDeviceAPIError extends DeviceAPIError {}
|
|
|
|
export class ServiceUnavailableAPIError extends DeviceAPIError {}
|