Browse Source

index: drastically improve error handling / messages for `create`

master
Guillermo Rauch 9 years ago
parent
commit
b83dbfb6ae
  1. 22
      lib/index.js

22
lib/index.js

@ -203,18 +203,24 @@ export default class Now extends EventEmitter {
if (this._debug) console.timeEnd('> [debug] /now/create'); if (this._debug) console.timeEnd('> [debug] /now/create');
// no retry on 4xx // no retry on 4xx
if (200 !== res.status && (400 <= res.status && 500 > res.status)) { let body;
if (this._debug) { try {
console.log('> [debug] bailing on creating due to %s', res.status); body = await res.json();
} } catch (err) {
return bail(responseError(res)); throw new Error('Unexpected response');
} }
if (200 !== res.status) { if (429 === res.status) {
throw new Error('Deployment initialization failed'); return bail(responseError(res));
} else if (res.status >= 400 && res.status < 500) {
const err = new Error(body.error.message);
err.userError = true;
return bail(err);
} else if (200 !== res.status) {
throw new Error(body.error.message);
} }
return res.json(); return body;
}); });
// we report about files whose sizes are too big // we report about files whose sizes are too big

Loading…
Cancel
Save