Add SubdomainError.BAD_FIELD

The CaaS backend return 400 for conflicts. We can use this to abort
early if there is a conflict in DNS entries. For example, if an app
subdomain already exists in DNS.

Part of #27
This commit is contained in:
Girish Ramakrishnan
2016-09-04 19:26:43 -07:00
parent 01064323c2
commit 2caf57d2c7
2 changed files with 3 additions and 0 deletions
+2
View File
@@ -41,6 +41,7 @@ function add(dnsConfig, zoneName, subdomain, type, values, callback) {
.send(data)
.end(function (error, result) {
if (error && !error.response) return callback(error);
if (result.statusCode === 400) return callback(new SubdomainError(SubdomainError.BAD_FIELD, result.body.message));
if (result.statusCode === 420) return callback(new SubdomainError(SubdomainError.STILL_BUSY));
if (result.statusCode !== 201) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));
@@ -108,6 +109,7 @@ function del(dnsConfig, zoneName, subdomain, type, values, callback) {
.send(data)
.end(function (error, result) {
if (error && !error.response) return callback(error);
if (result.statusCode === 400) return callback(new SubdomainError(SubdomainError.BAD_FIELD, result.body.message));
if (result.statusCode === 420) return callback(new SubdomainError(SubdomainError.STILL_BUSY));
if (result.statusCode === 404) return callback(new SubdomainError(SubdomainError.NOT_FOUND));
if (result.statusCode !== 204) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body)));