Skip to content

Commit

Permalink
feat(can-i-deploy): Add custom error type CannotDeployError for when …
Browse files Browse the repository at this point in the history
…the deploy check fails
  • Loading branch information
TimothyJones committed Oct 28, 2019
1 parent 3f7e86d commit 635b449
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/can-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import * as _ from 'underscore';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const checkTypes = require('check-types');

export class CannotDeployError extends Error {
output: CanDeployResponse | string;

constructor(output: CanDeployResponse | string) {
super('can-i-deploy result: it is not safe to deploy');
this.name = 'CannotDeployError';
this.output = output;
}
}

export class CanDeploy {
public static convertForSpawnBinary(
options: CanDeployOptions,
Expand Down Expand Up @@ -101,7 +111,7 @@ export class CanDeploy {
if (code === 0 && parsed.summary.deployable) {
return deferred.resolve(parsed);
}
return deferred.reject(parsed);
return deferred.reject(new CannotDeployError(parsed));
} catch (e) {
logger.error(`can-i-deploy produced non-json output:\n${result}`);
return deferred.reject(new Error(result));
Expand All @@ -114,7 +124,7 @@ export class CanDeploy {
}

logger.error(`can-i-deploy did not return success message:\n${result}`);
return deferred.reject(result);
return deferred.reject(new CannotDeployError(result));
});

return deferred.promise.timeout(
Expand Down

0 comments on commit 635b449

Please sign in to comment.