Final direct BadRequest removals
This commit is contained in:
parent
f3c7fb8bc6
commit
f8bdadfd9a
|
@ -1,6 +1,6 @@
|
|||
// @flow
|
||||
import httpErrors from 'http-errors';
|
||||
import querystring from 'querystring';
|
||||
import { InvalidRequestError } from '../../errors';
|
||||
import { type Context } from 'koa';
|
||||
|
||||
export default function pagination(options?: Object) {
|
||||
|
@ -24,7 +24,7 @@ export default function pagination(options?: Object) {
|
|||
offset = isNaN(offset) ? 0 : offset;
|
||||
|
||||
if (limit > opts.maxLimit) {
|
||||
throw httpErrors.BadRequest(
|
||||
throw new InvalidRequestError(
|
||||
`Pagination limit is too large (max ${opts.maxLimit})`
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// @flow
|
||||
import Koa from 'koa';
|
||||
import Router from 'koa-router';
|
||||
import httpErrors from 'http-errors';
|
||||
import { NotFoundError } from '../errors';
|
||||
import { Mailer } from '../mailer';
|
||||
|
||||
const emailPreviews = new Koa();
|
||||
|
@ -22,7 +22,7 @@ router.get('/:type/:format', async ctx => {
|
|||
if (Object.getOwnPropertyNames(previewMailer).includes(ctx.params.type)) {
|
||||
// $FlowIssue flow doesn't like this but we're ok with it
|
||||
previewMailer[ctx.params.type]('user@example.com');
|
||||
} else throw httpErrors.NotFound();
|
||||
} else throw new NotFoundError('Email template could not be found');
|
||||
}
|
||||
|
||||
if (!mailerOutput) return;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
import React from 'react';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import httpErrors from 'http-errors';
|
||||
import Koa from 'koa';
|
||||
import Router from 'koa-router';
|
||||
import sendfile from 'koa-sendfile';
|
||||
|
@ -11,6 +10,7 @@ import subdomainRedirect from './middlewares/subdomainRedirect';
|
|||
import renderpage from './utils/renderpage';
|
||||
import { slackAuth } from '../shared/utils/routeHelpers';
|
||||
import { robotsResponse } from './utils/robots';
|
||||
import { NotFoundError } from './errors';
|
||||
|
||||
import Home from './pages/Home';
|
||||
import About from './pages/About';
|
||||
|
@ -88,7 +88,7 @@ router.get('/robots.txt', ctx => (ctx.body = robotsResponse(ctx)));
|
|||
// catch all for react app
|
||||
router.get('*', async ctx => {
|
||||
await renderapp(ctx);
|
||||
if (!ctx.status) ctx.throw(httpErrors.NotFound());
|
||||
if (!ctx.status) ctx.throw(new NotFoundError());
|
||||
});
|
||||
|
||||
// middleware
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
// @flow
|
||||
import fetch from 'isomorphic-fetch';
|
||||
import querystring from 'querystring';
|
||||
import httpErrors from 'http-errors';
|
||||
import { InvalidRequestError } from './errors';
|
||||
|
||||
const SLACK_API_URL = 'https://slack.com/api';
|
||||
|
||||
export async function post(endpoint: string, body: Object) {
|
||||
let data;
|
||||
|
||||
const token = body.token;
|
||||
try {
|
||||
const token = body.token;
|
||||
const response = await fetch(`${SLACK_API_URL}/${endpoint}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -18,10 +19,10 @@ export async function post(endpoint: string, body: Object) {
|
|||
body: JSON.stringify(body),
|
||||
});
|
||||
data = await response.json();
|
||||
} catch (e) {
|
||||
throw httpErrors.BadRequest();
|
||||
} catch (err) {
|
||||
throw new InvalidRequestError(err.message);
|
||||
}
|
||||
if (!data.ok) throw httpErrors.BadRequest(data.error);
|
||||
if (!data.ok) throw new InvalidRequestError(data.error);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -33,10 +34,10 @@ export async function request(endpoint: string, body: Object) {
|
|||
`${SLACK_API_URL}/${endpoint}?${querystring.stringify(body)}`
|
||||
);
|
||||
data = await response.json();
|
||||
} catch (e) {
|
||||
throw httpErrors.BadRequest();
|
||||
} catch (err) {
|
||||
throw new InvalidRequestError(err.message);
|
||||
}
|
||||
if (!data.ok) throw httpErrors.BadRequest(data.error);
|
||||
if (!data.ok) throw new InvalidRequestError(data.error);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
Reference in New Issue