Improve error handling

This commit is contained in:
Tom Moor
2018-11-03 21:47:46 -07:00
parent 21b1c0747c
commit 6418712c47
5 changed files with 27 additions and 8 deletions

View File

@@ -51,7 +51,7 @@ class Details extends React.Component<Props> {
}); });
this.props.ui.showToast('Settings saved', 'success'); this.props.ui.showToast('Settings saved', 'success');
} catch (err) { } catch (err) {
this.props.ui.showToast('Could not save'); this.props.ui.showToast(err.message);
} }
}; };
@@ -127,14 +127,15 @@ class Details extends React.Component<Props> {
<Input <Input
label="Subdomain" label="Subdomain"
name="subdomain" name="subdomain"
value={this.subdomain} value={this.subdomain || ''}
onChange={this.handleSubdomainChange} onChange={this.handleSubdomainChange}
placeholder="Optional" placeholder="Optional"
autocomplete={false}
short short
/> />
{this.subdomain && ( {this.subdomain && (
<HelpText small> <HelpText small>
You will be able to access your wiki at{' '} You will access your knowledgebase at{' '}
<strong>{this.subdomain}.getoutline.com</strong> <strong>{this.subdomain}.getoutline.com</strong>
</HelpText> </HelpText>
)} )}

View File

@@ -68,6 +68,14 @@ class ApiClient {
const error = {}; const error = {};
error.statusCode = response.status; error.statusCode = response.status;
error.response = response; error.response = response;
try {
const data = await response.json();
error.message = data.message || '';
} catch (_err) {
// we're trying to parse an error so JSON may not be valid
}
throw error; throw error;
}; };

View File

@@ -21,9 +21,18 @@ const Team = sequelize.define(
allowNull: true, allowNull: true,
validate: { validate: {
isLowercase: true, isLowercase: true,
is: [/^[a-z\d-]+$/, 'i'], is: {
len: [4, 32], args: [/^[a-z\d-]+$/, 'i'],
notIn: [RESERVED_SUBDOMAINS], msg: 'Must be only alphanumeric and dashes',
},
len: {
args: [4, 32],
msg: 'Must be between 4 and 32 characters',
},
notIn: {
args: [RESERVED_SUBDOMAINS],
msg: 'You chose a restricted word, please try another.',
},
}, },
unique: true, unique: true,
}, },

View File

@@ -1,7 +1,7 @@
// @flow // @flow
import parseDomain from 'parse-domain'; import parseDomain from 'parse-domain';
export function stripSubdomain(hostname) { export function stripSubdomain(hostname: string) {
const parsed = parseDomain(hostname); const parsed = parseDomain(hostname);
if (parsed.tld) return `${parsed.domain}.${parsed.tld}`; if (parsed.tld) return `${parsed.domain}.${parsed.tld}`;
return parsed.domain; return parsed.domain;

View File

@@ -16,7 +16,8 @@ const definePlugin = new webpack.DefinePlugin({
DEPLOYMENT: JSON.stringify(process.env.DEPLOYMENT || 'hosted'), DEPLOYMENT: JSON.stringify(process.env.DEPLOYMENT || 'hosted'),
'process.env': { 'process.env': {
URL: JSON.stringify(process.env.URL), URL: JSON.stringify(process.env.URL),
SLACK_KEY: JSON.stringify(process.env.SLACK_KEY) SLACK_KEY: JSON.stringify(process.env.SLACK_KEY),
SUBDOMAINS_ENABLED: JSON.stringify(process.env.SUBDOMAINS_ENABLED)
} }
}); });