Commit e2dafff5 authored by Paul Kaplan's avatar Paul Kaplan

Include rate limit and 404 error types

parent 7c021b6a
...@@ -9,12 +9,16 @@ const Errors = keyMirror({ ...@@ -9,12 +9,16 @@ const Errors = keyMirror({
NETWORK: null, NETWORK: null,
SERVER: null, SERVER: null,
PERMISSION: null, PERMISSION: null,
DUPLICATE: null DUPLICATE: null,
UNKNOWN_USERNAME: null,
RATE_LIMIT: null
}); });
const normalizeError = (err, body, res) => { const normalizeError = (err, body, res) => {
if (err) return Errors.NETWORK; if (err) return Errors.NETWORK;
if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION; if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION;
if (res.statusCode === 404) return Errors.UNKNOWN_USERNAME;
if (res.statusCode === 429) return Errors.RATE_LIMIT;
if (res.statusCode !== 200) return Errors.SERVER; if (res.statusCode !== 200) return Errors.SERVER;
if (body && body.status === 'error') { if (body && body.status === 'error') {
if (body.message.indexOf('already a curator') !== -1) { if (body.message.indexOf('already a curator') !== -1) {
......
...@@ -9,12 +9,16 @@ import {projects} from './redux-modules'; ...@@ -9,12 +9,16 @@ import {projects} from './redux-modules';
const Errors = keyMirror({ const Errors = keyMirror({
NETWORK: null, NETWORK: null,
SERVER: null, SERVER: null,
PERMISSION: null PERMISSION: null,
UNKNOWN_PROJECT: null,
RATE_LIMIT: null
}); });
const normalizeError = (err, body, res) => { const normalizeError = (err, body, res) => {
if (err) return Errors.NETWORK; if (err) return Errors.NETWORK;
if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION; if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION;
if (res.statusCode === 404) return Errors.UNKNOWN_PROJECT;
if (res.statusCode === 429) return Errors.RATE_LIMIT;
if (res.statusCode !== 200) return Errors.SERVER; if (res.statusCode !== 200) return Errors.SERVER;
return null; return null;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment