Skip to content

Commit

Permalink
Fix the handling of user errors (#1959)
Browse files Browse the repository at this point in the history
* fix unexpected `size_limit_exceeded`

* fix unexpected `deployment_type_unsupported`

* fix unexpected `JSONError`

* check if err.sizeLimit exists
  • Loading branch information
juliangruber authored and leo committed Mar 15, 2019
1 parent 402c4e7 commit 803b1ae
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/commands/deploy/latest.js
Expand Up @@ -460,6 +460,13 @@ export default async function main(
error(message);
}

if (err.code === 'size_limit_exceeded') {
const { sizeLimit = 0 } = err;
const message = `File size limit exceeded (${bytes(sizeLimit)})`;
error(message);
return 1;
}

handleError(err);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/deploy/legacy.js
Expand Up @@ -421,7 +421,7 @@ async function sync({
'multiple_manifests'
];

if (err.code && print.includes(err.code)) {
if (err.code && print.includes(err.code) || err.name === 'JSONError') {
error(err.message);
return 1;
}
Expand Down
7 changes: 6 additions & 1 deletion src/commands/scale.js
Expand Up @@ -18,7 +18,7 @@ import getMinFromArgs from '../util/scale/get-min-from-args';
import patchDeploymentScale from '../util/scale/patch-deployment-scale';
import waitVerifyDeploymentScale from '../util/scale/wait-verify-deployment-scale';
import { handleError } from '../util/error';
import { VerifyScaleTimeout } from '../util/errors-ts';
import { VerifyScaleTimeout, DeploymentTypeUnsupported } from '../util/errors-ts';
import {
DeploymentNotFound,
DeploymentPermissionDenied,
Expand Down Expand Up @@ -279,6 +279,11 @@ export default async function main(ctx) {
now.close();
return 1;
}
if (result instanceof DeploymentTypeUnsupported) {
output.error(`This region only accepts Serverless Docker Deployments.`);
now.close();
return 1;
}

console.log(
`${chalk.gray('>')} Scale rules for ${dcs
Expand Down
10 changes: 10 additions & 0 deletions src/util/errors-ts.ts
Expand Up @@ -535,6 +535,16 @@ export class DeploymentPermissionDenied extends NowError<
}
}

export class DeploymentTypeUnsupported extends NowError<'DEPLOYMENT_TYPE_UNSUPPORTED', {}> {
constructor() {
super({
code: 'DEPLOYMENT_TYPE_UNSUPPORTED',
meta: {},
message: `This region only accepts Serverless Docker Deployments`
});
}
}

/**
* Returned when we try to create an alias but the API returns an error telling
* that the given alias is not valid.
Expand Down
3 changes: 3 additions & 0 deletions src/util/scale/patch-deployment-scale.ts
Expand Up @@ -46,6 +46,9 @@ export default async function patchDeploymentScale(
if (error.code === 'not_supported_min_scale_slots') {
return new Errors.NotSupportedMinScaleSlots(url);
}
if (error.code === 'deployment_type_unsupported') {
return new Errors.DeploymentTypeUnsupported();
}

throw error;
}
Expand Down

0 comments on commit 803b1ae

Please sign in to comment.