Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

fix(client): basket errors throw 500 #2711

Closed
wants to merge 1 commit into from

Conversation

TDA
Copy link
Contributor

@TDA TDA commented Jul 8, 2015

Fixes #2644
Should be green
@vladikoff
@shane-tomlinson

@@ -30,7 +30,8 @@ define([
url: url,
type: method,
accessToken: accessToken,
data: data
data: data,
timeout: 2500
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the subscribe/unsubscribe issue, and returns an error as expected.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make 2500 a named constant like DEFAULT_XHR_TIMEOUT_MS and allow an override to be passed in to the MarketingEmailClient constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@pdehaan pdehaan added the WIP label Jul 8, 2015
self.$('.spinner').hide();
self.displayError(err);
self.$('.spinner').hide(); // <-- I don't think this ever works as intended
self.displayError(err); // <-- This logs to the console, but should actually display .error
return false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self returns the proper object (a div with class communication-preferences as expected), but fails to hide the .spinner or display the .error class.

@vladikoff vladikoff changed the title fix(client): basket errors throw 500 WIP fix(client): basket errors throw 500 Jul 8, 2015
$('.spinner').hide();
$('.error').html(err).show();
setTimeout(function() {
self.navigate('/');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just inform the user, without doing a redirect, for now.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the service is unavailable, we should probably hide the subscribe & unsubscribe buttons, or just not render them in the first place.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also log any error that occurs, it doesn't look like that is being done unless the user is redirected to /unexpected_error`, which is both unfortunate and unexpected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the error is thrown at the /lookup-user, the buttons arent displayed at all. Actually nothing is displayed, so I added only the error message now, is that all right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shane-tomlinson I did not get the logging part, I dont see anything being logged for the unexpected_error page.

@TDA TDA force-pushed the issue-2644-basket-500-errors branch 2 times, most recently from d8b57ea to 6392c11 Compare July 9, 2015 19:25
@TDA TDA removed the WIP label Jul 9, 2015
@TDA TDA changed the title WIP fix(client): basket errors throw 500 fix(client): basket errors throw 500 Jul 9, 2015
@TDA
Copy link
Contributor Author

TDA commented Jul 9, 2015

r? @vladikoff @shane-tomlinson

@rfk rfk added this to the train 42 milestone Jul 11, 2015
@jrgm
Copy link
Contributor

jrgm commented Jul 12, 2015

So, re: https://bugzilla.mozilla.org/show_bug.cgi?id=1182679 it seems our handling of 400 responses needs some work too.

@TDA
Copy link
Contributor Author

TDA commented Jul 12, 2015

@jrgm What do you suggest jrgm? Do we consider that a separate issue, or try to fix that in this? I think the former, but let me know if its the latter :)

return emailPrefs.fetch()
.fail(function (err) {
if (MarketingEmailErrors.is(err, 'UNKNOWN_EMAIL')) {
// user has not yet opted in to Basket yet. Ignore.
return;
}
if (MarketingEmailErrors.is(err, 'SERVICE_UNAVAILABLE')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove the if statement and use this code generically + log to the console.

@TDA TDA force-pushed the issue-2644-basket-500-errors branch 3 times, most recently from 2ece498 to 1be0c10 Compare July 14, 2015 16:49
@TDA
Copy link
Contributor Author

TDA commented Jul 14, 2015

@shane-tomlinson final r?

@vladikoff
Copy link
Contributor

@shane-tomlinson @TDA we probably need unit tests for this behaviour

@TDA
Copy link
Contributor Author

TDA commented Jul 14, 2015

@vladikoff Isnt there a test for this already in /app/tests/spec/views/settings?

it('shows any other fetch errors', function () {
        emailPrefsModel.fetch.restore();
        sinon.stub(emailPrefsModel, 'fetch', function () {
          return p.reject(MarketingEmailErrors.toError('USAGE_ERROR'));
        });

        return render()
          .then(function () {
            assert.isTrue(view.isErrorVisible());
          });

@TDA TDA force-pushed the issue-2644-basket-500-errors branch 3 times, most recently from ce5317d to b4eccc4 Compare July 14, 2015 23:22
@shane-tomlinson
Copy link

OK, I think this is going to be slightly more complex than I thought. When testing locally, I see the following when opening "communication preferences":

screen shot 2015-07-15 at 16 43 02

The problems:

  • There should be no Error: before the actual error. When printing the error, I think err should be err.message || err)
  • The user has no way to go back.

I'm trying to think of the best way to handle this.

I think it will be to save the error to an instance variable, allow the page to display, and in the template, check if there is an error. If an error occurred, then print the error but not the rest of the form. For a reference of another view that does this, see complete_signup.js

@shane-tomlinson
Copy link

When printing the error, I think err should be err.message || err)

Ahha, complete_signup.js uses self.translateError(err) to handle this.

@TDA TDA force-pushed the issue-2644-basket-500-errors branch from b4eccc4 to 1c3f79e Compare July 16, 2015 17:37
@TDA
Copy link
Contributor Author

TDA commented Jul 16, 2015

@shane-tomlinson Should be good to go once Travis and CCI turn green :)

// View isnt rendered yet, so display the spinner manually.
$('.spinner').hide();
self._error = self.translateError(err);
return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nix this return

@TDA TDA force-pushed the issue-2644-basket-500-errors branch 3 times, most recently from efd0435 to 0c17199 Compare July 16, 2015 23:03
return this.toError('UNEXPECTED_ERROR');
}

return this.toError(errObj.errno);
var normalizedError = this.toError(serverError.errno);
normalizedError.code = serverError.code;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment above this line about what the code represents and why the code is transferred across?

@TDA TDA force-pushed the issue-2644-basket-500-errors branch from 0c17199 to da8c5db Compare July 16, 2015 23:49
Fixes mozilla#2644
set a timeout for ajax requests
display error to user and log to console
handles both 400 and 500 errors
@TDA TDA force-pushed the issue-2644-basket-500-errors branch from da8c5db to a337b4e Compare July 17, 2015 00:00
@shane-tomlinson
Copy link

Manually merged in 70b9df4, closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants