diff --git a/js/actions/edition_actions.js b/js/actions/edition_actions.js index 9563ed92..1727deff 100644 --- a/js/actions/edition_actions.js +++ b/js/actions/edition_actions.js @@ -9,6 +9,7 @@ class EditionActions { 'fetchEdition', 'successFetchEdition', 'successFetchCoa', + 'flushEdition', 'errorCoa', 'errorEdition' ); diff --git a/js/components/ascribe_detail/edition.js b/js/components/ascribe_detail/edition.js index 567c7d7f..d12d2a41 100644 --- a/js/components/ascribe_detail/edition.js +++ b/js/components/ascribe_detail/edition.js @@ -39,6 +39,7 @@ let Edition = React.createClass({ actionPanelButtonListType: React.PropTypes.func, furtherDetailsType: React.PropTypes.func, edition: React.PropTypes.object, + coaError: React.PropTypes.object, currentUser: React.PropTypes.object, loadEdition: React.PropTypes.func }, @@ -77,7 +78,9 @@ let Edition = React.createClass({ title={getLangText('Certificate of Authenticity')} show={this.props.edition.acl.acl_coa === true}> + coa={this.props.edition.coa} + coaError={this.props.coaError} + editionId={this.props.edition.bitcoin_id}/> +

{getLangText('There was an error generating your Certificate of Authenticity.')}

+

+ {getLangText('Try to refresh the page. If this happens repeatedly, please ')} + {getLangText('contact us')}. +

+ + ); + } if(this.props.coa && this.props.coa.url_safe) { return (
diff --git a/js/components/ascribe_detail/edition_container.js b/js/components/ascribe_detail/edition_container.js index 2a0e7d5e..add06ccd 100644 --- a/js/components/ascribe_detail/edition_container.js +++ b/js/components/ascribe_detail/edition_container.js @@ -48,6 +48,7 @@ let EditionContainer = React.createClass({ // just reset the edition that is saved in the edition store // as it will otherwise display wrong/old data once the user loads // the edition detail a second time + EditionActions.flushEdition(); EditionActions.fetchEdition(this.props.params.editionId); UserActions.fetchCurrentUser(); @@ -95,6 +96,7 @@ let EditionContainer = React.createClass({ actionPanelButtonListType={this.props.actionPanelButtonListType} furtherDetailsType={this.props.furtherDetailsType} edition={this.state.edition} + coaError={this.state.coaMeta.err} currentUser={this.state.currentUser} loadEdition={() => EditionActions.fetchEdition(this.props.params.editionId)} /> ); diff --git a/js/fetchers/coa_fetcher.js b/js/fetchers/coa_fetcher.js deleted file mode 100644 index e4956c66..00000000 --- a/js/fetchers/coa_fetcher.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -import requests from '../utils/requests'; - -let CoaFetcher = { - /** - * Fetch one user from the API. - * If no arg is supplied, load the current user - */ - fetchOne(id) { - return requests.get('coa', {'id': id}); - }, - create(bitcoinId) { - return requests.post('coa_create', {body: {'bitcoin_id': bitcoinId}}); - } -}; - -export default CoaFetcher; diff --git a/js/fetchers/edition_fetcher.js b/js/fetchers/edition_fetcher.js deleted file mode 100644 index 2d289a3e..00000000 --- a/js/fetchers/edition_fetcher.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -import requests from '../utils/requests'; - -let EditionFetcher = { - /** - * Fetch one user from the API. - * If no arg is supplied, load the current user - */ - fetchOne(editionId) { - return requests.get('edition', {'bitcoin_id': editionId}); - } -}; - -export default EditionFetcher; diff --git a/js/stores/edition_store.js b/js/stores/edition_store.js index 212dc25c..fbe070e1 100644 --- a/js/stores/edition_store.js +++ b/js/stores/edition_store.js @@ -36,7 +36,7 @@ class EditionStore { if(this.edition && this.edition.coa && typeof this.edition.coa.constructor !== Object) { this.getInstance().lookupCoa(); - } else if(this.edition && !this.edition.coa) { + } else if(this.edition && !this.edition.coa && this.edition.acl.acl_coa) { this.getInstance().performCreateCoa(); } } @@ -46,11 +46,22 @@ class EditionStore { this.edition.coa = coa; } - onEditionError(err) { + onFlushEdition() { + this.edition = null; + this.editionMeta = { + err: null, + idToFetch: null + }; + this.coaMeta = { + err: null + }; + } + + onErrorEdition(err) { this.editionMeta.err = err; } - onCoaError(err) { + onErrorCoa(err) { this.coaMeta.err = err; } } diff --git a/js/utils/requests.js b/js/utils/requests.js index 9195661d..d3f5d964 100644 --- a/js/utils/requests.js +++ b/js/utils/requests.js @@ -12,7 +12,14 @@ import { argsToQueryParams } from '../utils/url_utils'; class Requests { unpackResponse(response) { if (response.status >= 500) { - throw new Error(response.status + ' - ' + response.statusText + ' - on URL:' + response.url); + let err = new Error(response.status + ' - ' + response.statusText + ' - on URL:' + response.url); + response + .text() + .then((resText) => JSON.parse(resText)) + .then((resJSON) => { + err = new Error(resJSON.errors.pop()); + }) + .catch(() => { throw err; }); } return Q.Promise((resolve, reject) => {