From 3ce63c33bf9999a989c757e551eed0155c13529b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Mon, 7 Dec 2015 11:48:28 +0100 Subject: [PATCH] Finalize ReactError component --- js/components/ascribe_detail/edition_container.js | 2 +- js/components/ascribe_detail/piece_container.js | 2 +- js/components/error_not_found_page.js | 2 +- js/mixins/react_error.js | 9 ++++++--- js/models/errors.js | 4 +--- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/js/components/ascribe_detail/edition_container.js b/js/components/ascribe_detail/edition_container.js index c49b87ba..fdc18c39 100644 --- a/js/components/ascribe_detail/edition_container.js +++ b/js/components/ascribe_detail/edition_container.js @@ -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."))); } }, diff --git a/js/components/ascribe_detail/piece_container.js b/js/components/ascribe_detail/piece_container.js index 0b4cfbb1..44b9357c 100644 --- a/js/components/ascribe_detail/piece_container.js +++ b/js/components/ascribe_detail/piece_container.js @@ -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."))); } }, diff --git a/js/components/error_not_found_page.js b/js/components/error_not_found_page.js index 64776f2f..0e111ce7 100644 --- a/js/components/error_not_found_page.js +++ b/js/components/error_not_found_page.js @@ -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.") }; }, diff --git a/js/mixins/react_error.js b/js/mixins/react_error.js index 1169a069..14f33a61 100644 --- a/js/mixins/react_error.js +++ b/js/mixins/react_error.js @@ -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); + } } }; diff --git a/js/models/errors.js b/js/models/errors.js index e748d953..4573afe4 100644 --- a/js/models/errors.js +++ b/js/models/errors.js @@ -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 = () => ;