Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the handling of user errors #1958

Merged
merged 6 commits into from Mar 13, 2019
Copy path View file
@@ -32,7 +32,8 @@ import {
DomainVerificationFailed,
TooManyCertificates,
TooManyRequests,
InvalidDomain
InvalidDomain,
FileSizeLimitExceeded
} from '../../util/errors-ts';
import { SchemaValidationFailed } from '../../util/errors';

@@ -358,7 +359,8 @@ export default async function main(
firstDeployCall instanceof SchemaValidationFailed ||
firstDeployCall instanceof TooManyCertificates ||
firstDeployCall instanceof TooManyRequests ||
firstDeployCall instanceof InvalidDomain
firstDeployCall instanceof InvalidDomain ||
firstDeployCall instanceof FileSizeLimitExceeded
) {
handleCreateDeployError(output, firstDeployCall);
return 1;
@@ -433,7 +435,8 @@ export default async function main(
secondDeployCall instanceof DomainVerificationFailed ||
secondDeployCall instanceof SchemaValidationFailed ||
secondDeployCall instanceof TooManyCertificates ||
secondDeployCall instanceof TooManyRequests
secondDeployCall instanceof TooManyRequests ||
secondDeployCall instanceof FileSizeLimitExceeded
) {
handleCreateDeployError(output, secondDeployCall);
return 1;
@@ -693,6 +696,10 @@ function handleCreateDeployError(output, error) {
);
return 1;
}
if (error instanceof FileSizeLimitExceeded) {
output.error(`File size limit exceeded.`);

This comment has been minimized.

Copy link
@juliangruber

juliangruber Mar 13, 2019

Author Contributor

should there be a more user friendly error message here?

return 1;
}

return error;
}
Copy path View file
@@ -1,5 +1,5 @@
import chalk from 'chalk';
import { DomainNotFound, DNSPermissionDenied } from '../../util/errors-ts';
import { DomainNotFound, DNSPermissionDenied, DNSInvalidPort, DNSInvalidType } from '../../util/errors-ts';
import { NowContext } from '../../types';
import { Output } from '../../util/output';
import addDNSRecord from '../../util/dns/add-dns-record';
@@ -68,6 +68,24 @@ export default async function add(
return 1;
}

if (record instanceof DNSInvalidPort) {
output.error(
`Invalid <port> parameter. A number was expected ${chalk.gray(addStamp())}`
);
return 1;
}

if (record instanceof DNSInvalidType) {
output.error(
`Invalid <type> parameter "${
record.meta.type
}". Expected one of A, AAAA, ALIAS, CAA, CNAME, MX, SRV, TXT ${
chalk.gray(addStamp())
}`
);
return 1;
}

if (record instanceof Error) {
output.error(record.message);
return 1;
@@ -36,6 +36,10 @@ export default async function createDeploy(
);
}

if (error.code === 'size_limit_exceeded') {
return new ERRORS_TS.FileSizeLimitExceeded()
}

// If the cert is missing we try to generate a new one and the retry
if (error.code === 'cert_missing') {
const result = await generateCertForDeploy(
Copy path View file
@@ -1,5 +1,5 @@
import Client from '../client';
import { DomainNotFound, DNSPermissionDenied } from '../errors-ts';
import { DomainNotFound, DNSPermissionDenied, DNSInvalidPort, DNSInvalidType } from '../errors-ts';
import { DNSRecordData } from '../../types';

type Response = {
@@ -18,6 +18,14 @@ export default async function addDNSRecord(
});
return record;
} catch (error) {
if (error.status === 400 && error.code === 'invalid_type') {
return new DNSInvalidType(recordData.type);
}

if (error.status === 400 && error.message.includes('port')) {
return new DNSInvalidPort();
}

if (error.status === 400) {
return error;
}
Copy path View file
@@ -803,6 +803,29 @@ export class DNSPermissionDenied extends NowError<
}
}

export class DNSInvalidPort extends NowError<'DNS_INVALID_PORT', {}> {
constructor() {
super({
code: 'DNS_INVALID_PORT',
meta: {},
message: `Invalid <port> parameter. A number was expected`
});
}
}

export class DNSInvalidType extends NowError<
'DNS_INVALID_TYPE',
{ type: string }
> {
constructor(type: string) {
super({
code: 'DNS_INVALID_TYPE',
meta: { type },
message: `Invalid <type> parameter "${type}". Expected one of A, AAAA, ALIAS, CAA, CNAME, MX, SRV, TXT`
});
}
}

export class DomainRemovalConflict extends NowError<
'domain_removal_conflict',
{
@@ -908,3 +931,13 @@ export class InvalidMoveToken extends NowError<
});
}
}

export class FileSizeLimitExceeded extends NowError<'FILE_SIZE_LIMIT_EXCEEDED', {}> {
constructor() {
super({
code: 'FILE_SIZE_LIMIT_EXCEEDED',
meta: {},
message :'File size limit exceeded'
})
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.