Skip to content

Commit

Permalink
print actual error messages if debug is set
Browse files Browse the repository at this point in the history
  • Loading branch information
Sid Nutulapati committed Mar 19, 2019
1 parent fb6dbf2 commit f9de095
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
25 changes: 23 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ class ServerlessCustomDomain {
});
}
} catch (err) {
this.logIfDebug(err);
throw Error(`Error: Could not list certificates in Certificate Manager.\n${err}`);
}
if (certificateArn == null) {
Expand All @@ -294,6 +295,7 @@ class ServerlessCustomDomain {
domainInfo = await this.apigateway.getDomainName({ domainName: this.givenDomainName }).promise();
return new DomainInfo(domainInfo);
} catch (err) {
this.logIfDebug(err);
if (err.code === "NotFoundException") {
throw new Error(`Error: ${this.givenDomainName} not found.`);
}
Expand Down Expand Up @@ -325,7 +327,8 @@ class ServerlessCustomDomain {
let createdDomain = {};
try {
createdDomain = await this.apigateway.createDomainName(params).promise();
} catch {
} catch (err) {
this.logIfDebug(err);
throw new Error(`Error: Failed to create custom domain ${this.givenDomainName}\n`);
}
return new DomainInfo(createdDomain);
Expand All @@ -342,7 +345,8 @@ class ServerlessCustomDomain {
// Make API call
try {
await this.apigateway.deleteDomainName(params).promise();
} catch {
} catch (err) {
this.logIfDebug(err);
throw new Error(`Error: Failed to delete custom domain ${this.givenDomainName}\n`);
}
}
Expand Down Expand Up @@ -389,6 +393,7 @@ class ServerlessCustomDomain {
try {
await this.route53.changeResourceRecordSets(params).promise();
} catch (err) {
this.logIfDebug(err);
throw new Error(`Error: Failed to ${action} A Alias for ${this.givenDomainName}\n`);
}
}
Expand Down Expand Up @@ -449,6 +454,7 @@ class ServerlessCustomDomain {
return hostedZoneId.substring(startPos, endPos);
}
} catch (err) {
this.logIfDebug(err);
throw new Error(`Error: Unable to list hosted zones in Route53.\n${err}`);
}
throw new Error(`Error: Could not find hosted zone "${this.givenDomainName}"`);
Expand All @@ -463,6 +469,7 @@ class ServerlessCustomDomain {
try {
basepathInfo = await this.apigateway.getBasePathMappings(params).promise();
} catch (err) {
this.logIfDebug(err);
throw new Error(`Error: Unable to get BasePathMappings for ${this.givenDomainName}`);
}
if (basepathInfo.items !== undefined && basepathInfo.items instanceof Array) {
Expand Down Expand Up @@ -491,6 +498,7 @@ class ServerlessCustomDomain {
await this.apigateway.createBasePathMapping(params).promise();
this.serverless.cli.log("Created basepath mapping.");
} catch (err) {
this.logIfDebug(err);
throw new Error(`Error: Unable to create basepath mapping.\n`);
}
}
Expand All @@ -515,6 +523,7 @@ class ServerlessCustomDomain {
await this.apigateway.updateBasePathMapping(params).promise();
this.serverless.cli.log("Updated basepath mapping.");
} catch (err) {
this.logIfDebug(err);
throw new Error(`Error: Unable to update basepath mapping.\n`);
}
}
Expand All @@ -539,6 +548,7 @@ class ServerlessCustomDomain {
try {
response = await this.cloudformation.describeStackResource(params).promise();
} catch (err) {
this.logIfDebug(err);
throw new Error(`Error: Failed to find CloudFormation resources for ${this.givenDomainName}\n`);
}
const restApiId = response.StackResourceDetail.PhysicalResourceId;
Expand All @@ -561,6 +571,7 @@ class ServerlessCustomDomain {
await this.apigateway.deleteBasePathMapping(params).promise();
this.serverless.cli.log("Removed basepath mapping.");
} catch (err) {
this.logIfDebug(err);
this.serverless.cli.log("Unable to remove basepath mapping.");
}
}
Expand Down Expand Up @@ -597,6 +608,16 @@ class ServerlessCustomDomain {
this.serverless.cli.consoleLog(chalk.yellow("Distribution Domain Name"));
this.serverless.cli.consoleLog(` ${domainInfo.domainName}`);
}

/**
* Logs message if SLS_DEBUG is set
* @param message message to be printed
*/
private logIfDebug(message: any): void {
if (process.env.SLS_DEBUG) {
this.serverless.cli.log(message, "Serverless Domain Manager");
}
}
}

export = ServerlessCustomDomain;
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
},
"dependencies": {
"@types/chai-spies": "^1.0.0",
"@types/node": "^11.11.3",
"aws-sdk": "^2.177.0",
"chalk": "^2.4.1"
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"rootDir": ".",
"target": "es6",
"sourceMap": false,
"outDir": "dist"
"outDir": "dist",
"types": ["node"]
},
"include": [
"*.ts"
Expand Down
2 changes: 1 addition & 1 deletion types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface ServerlessInstance { // tslint:disable-line
},
};
cli: {
log(str: string),
log(str: string, entity?: string),
consoleLog(str: any),
};
}
Expand Down

0 comments on commit f9de095

Please sign in to comment.