Skip to content

Commit

Permalink
fix: Remove instanceof checks for errors (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
taion committed Mar 5, 2019
1 parent c700bd2 commit ec79c30
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ These behave similarly to their counterparts above, except that the options obje
Found exposes lower-level functionality for doing server-side rendering for use with your own Redux store, as with `createConnectedRouter` above. On the server, use `getStoreRenderArgs` to get a promise for the arguments to your `render` function.
```js
import { getStoreRenderArgs, RedirectException } from 'found';
import { getStoreRenderArgs } from 'found';

/* ... */

Expand All @@ -939,7 +939,7 @@ app.use(async (req, res) => {
resolver,
});
} catch (e) {
if (e instanceof RedirectException) {
if (e.isFoundRedirectException) {
res.redirect(302, store.farce.createHref(e.location));
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/HttpError.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default class HttpError {
isFoundHttpError = true;

constructor(status, data) {
this.status = status;
this.data = data;
Expand Down
2 changes: 2 additions & 0 deletions src/RedirectException.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// This isn't really an error.
export default class RedirectException {
isFoundRedirectException = true;

constructor(location) {
this.location = location;
}
Expand Down
3 changes: 1 addition & 2 deletions src/createBaseRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import StaticContainer from 'react-static-container';
import warning from 'warning';

import { routerShape } from './PropTypes';
import RedirectException from './RedirectException';
import createRender from './createRender';
import resolveRenderArgs from './utils/resolveRenderArgs';

Expand Down Expand Up @@ -144,7 +143,7 @@ export default function createBaseRouter({
}
}
} catch (e) {
if (e instanceof RedirectException) {
if (e.isFoundRedirectException) {
this.props.router.replace(e.location);
return;
}
Expand Down
3 changes: 1 addition & 2 deletions src/server/getFarceResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React from 'react';
import { Provider } from 'react-redux';

import getStoreRenderArgs from '../getStoreRenderArgs';
import RedirectException from '../RedirectException';
import defaultResolver from '../resolver';
import createFarceStore from '../utils/createFarceStore';

Expand Down Expand Up @@ -33,7 +32,7 @@ export default async function getFarceResult({
resolver,
});
} catch (e) {
if (e instanceof RedirectException) {
if (e.isFoundRedirectException) {
// The store is not exposed to the user, so we need to build the redirect
// URL here.
return {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/resolveRenderArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default async function* resolveRenderArgs({
};
}
} catch (e) {
if (e instanceof HttpError) {
if (e.isFoundHttpError) {
yield { ...augmentedMatch, error: e };
return;
}
Expand Down

0 comments on commit ec79c30

Please sign in to comment.