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
@@ -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;
Copy path View file
@@ -50,7 +50,7 @@ if (!insidePkg) {

// Configure the error reporting system
Sentry.init({
dsn: 'https://417d8c347b324670b668aca646256352@sentry.io/1323225',
dsn: 'https://26a24e59ba954011919a524b341b6ab5@sentry.io/1323225',
release: `now-cli@${pkg.version}`,
environment: pkg.version.includes('canary') ? 'canary' : 'stable'
});
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',
{
Copy path View file
@@ -43,7 +43,8 @@ export default async (sentry, error, apiUrl, configFiles) => {
scope.setTag('currentTeam', team.id);
}

scope.setExtra('argv', process.argv);
// Disable sending `argv` until we properly remove sensitive data
// scope.setExtra('argv', process.argv);

sentry.captureException(error);
});
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.