1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 09:23:13 +01:00

Finalize ReactError component

This commit is contained in:
Tim Daubenschütz 2015-12-07 11:48:28 +01:00
parent 0a67766aba
commit 3ce63c33bf
5 changed files with 10 additions and 9 deletions

View File

@ -55,7 +55,7 @@ let EditionContainer = React.createClass({
const { editionError } = this.state;
if(editionError && editionError.status === 404) {
this.throws(new ResourceNotFoundError(getLangText('Oops, the edition you\'re looking for doesn\'t exist.')));
this.throws(new ResourceNotFoundError(getLangText("Oops, the edition you're looking for doesn't exist.")));
}
},

View File

@ -86,7 +86,7 @@ let PieceContainer = React.createClass({
const { pieceError } = this.state;
if(pieceError && pieceError.status === 404) {
this.throws(new ResourceNotFoundError(getLangText('Oops, the piece you\'re looking for doesn\'t exist.')));
this.throws(new ResourceNotFoundError(getLangText("Oops, the piece you're looking for doesn't exist.")));
}
},

View File

@ -12,7 +12,7 @@ let ErrorNotFoundPage = React.createClass({
getDefaultProps() {
return {
message: getLangText('Oops, the page you are looking for does not exist.')
message: getLangText("Oops, the page you are looking for doesn't exist.")
};
},

View File

@ -4,9 +4,12 @@ import invariant from 'invariant';
const ReactError = {
throws(err) {
invariant(err.handler, 'Error thrown to ReactError did not have a `handler` function');
console.logGlobal('Error thrown to ReactError did not have a `handler` function');
err.handler(this, err);
if(!err.handler) {
invariant(err.handler, 'Error thrown to ReactError did not have a `handler` function');
console.logGlobal('Error thrown to ReactError did not have a `handler` function');
} else {
err.handler(this, err);
}
}
};

View File

@ -19,9 +19,7 @@ export class ResourceNotFoundError extends Error {
}
handler(component, err) {
const { displayName } = component.constructor;
const monkeyPatchedKey = typeof displayName === 'string' ? `_${displayName}MonkeyPatched`
: '_monkeyPatched';
const monkeyPatchedKey = `_${this.name}MonkeyPatched`;
if(!component.state[monkeyPatchedKey]) {
component.render = () => <ErrorNotFoundPage message={err.message} />;