From 64ceb2ae56f5f7dc3219ca5753c0121b2c308496 Mon Sep 17 00:00:00 2001 From: Ray Schamp Date: Tue, 13 Dec 2016 12:12:23 -0500 Subject: [PATCH] Provide fallback error messages In case the response does not supply `msg` or `errors`, provide a default. If `registrationError(s)` is empty, we do not show the error card, which causes "silent" failures. --- src/l10n.json | 1 + .../studentcompleteregistration.jsx | 11 +++++++++-- src/views/studentregistration/studentregistration.jsx | 10 +++++++--- src/views/teacherregistration/teacherregistration.jsx | 10 +++++++--- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/l10n.json b/src/l10n.json index c0e71af31..c26ca761a 100644 --- a/src/l10n.json +++ b/src/l10n.json @@ -110,6 +110,7 @@ "registration.choosePasswordStepTitle": "Create a password", "registration.choosePasswordStepTooltip": "Don't use your name or anything that's easy for someone else to guess.", "registration.classroomApiGeneralError": "Sorry, we could not find the registration information for this class", + "registration.generalError": "Sorry, an unexpected error occurred.", "registration.classroomInviteExistingStudentStepDescription": "you have been invited to join the class:", "registration.classroomInviteNewStudentStepDescription": "has invited you to join the class:", "registration.confirmYourEmail": "Confirm Your Email", diff --git a/src/views/studentcompleteregistration/studentcompleteregistration.jsx b/src/views/studentcompleteregistration/studentcompleteregistration.jsx index e8d429d54..e337470d7 100644 --- a/src/views/studentcompleteregistration/studentcompleteregistration.jsx +++ b/src/views/studentcompleteregistration/studentcompleteregistration.jsx @@ -86,11 +86,18 @@ var StudentCompleteRegistration = intl.injectIntl(React.createClass({ method: 'post', useCsrf: true, formData: submittedData - }, function (err, body) { + }, function (err, body, res) { this.setState({waiting: false}); if (err) return this.setState({registrationError: err}); if (body.success) return this.advanceStep(formData); - this.setState({registrationErrors: body.errors}); + this.setState({ + registrationErrors: + body.errors || { + __all__: + this.props.intl.formatMessage({id: 'registration.generalError'}) + + ' (' + res.statusCode + ')' + } + }); }.bind(this)); }, goToClass: function () { diff --git a/src/views/studentregistration/studentregistration.jsx b/src/views/studentregistration/studentregistration.jsx index 5400b11d6..bb22c8a31 100644 --- a/src/views/studentregistration/studentregistration.jsx +++ b/src/views/studentregistration/studentregistration.jsx @@ -78,11 +78,15 @@ var StudentRegistration = intl.injectIntl(React.createClass({ classroom_id: this.props.classroomId, classroom_token: this.props.classroomToken } - }, function (err, res) { + }, function (err, body, res) { this.setState({waiting: false}); if (err) return this.setState({registrationError: err}); - if (res[0].success) return this.advanceStep(formData); - this.setState({registrationError: res[0].msg}); + if (body[0].success) return this.advanceStep(formData); + this.setState({ + registrationError: + body[0].msg || + this.props.intl.formatMessage({id: 'registration.generalError'}) + ' (' + res.statusCode + ')' + }); }.bind(this)); }, goToClass: function () { diff --git a/src/views/teacherregistration/teacherregistration.jsx b/src/views/teacherregistration/teacherregistration.jsx index b278a8101..45e22956e 100644 --- a/src/views/teacherregistration/teacherregistration.jsx +++ b/src/views/teacherregistration/teacherregistration.jsx @@ -66,14 +66,18 @@ var TeacherRegistration = React.createClass({ address_zip: this.state.formData.address.zip, how_use_scratch: this.state.formData.useScratch } - }, function (err, res) { + }, function (err, body, res) { this.setState({waiting: false}); if (err) return this.setState({registrationError: err}); - if (res[0].success) { + if (body[0].success) { this.props.dispatch(sessionActions.refreshSession()); return this.advanceStep(formData); } - this.setState({registrationError: res[0].msg}); + this.setState({ + registrationError: + body[0].msg || + this.props.intl.formatMessage({id: 'registration.generalError'}) + ' (' + res.statusCode + ')' + }); }.bind(this)); },