Make monkeyPatched key specific to component's displayName

This commit is contained in:
Tim Daubenschütz 2015-12-07 10:57:49 +01:00
parent 4fe10bb887
commit 3374862edf
3 changed files with 8 additions and 4 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('Ups, 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('Ups, 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

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