Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error when flagging when logged out #374

Merged
merged 1 commit into from
May 4, 2017

Conversation

seanh
Copy link
Contributor

@seanh seanh commented Apr 26, 2017

Improve the error message that's shown to the user when trying to flag
an annotation while logged out.

Instead of showing a "404 Not Found. Either the resource you requested
doesn't exist, or you are not currently authorized to see it." error
from the server, show a friendlier "You must be logged in to report an
annotation" message:

peek 2017-04-26 17-26

This is done client-side by checking whether the user is logged in when
they click the flag button, and if not showing an error instead of
sending the flag request to the API. This is because the API doesn't
respond with a unique "You must be logged in to flag" error that the
client could depend on, it just returns a 404, which could be for a
number of reasons (e.g. the annotation no longer exists).

I am using the preventOpenDuplicates: true option to angular-toastr so
that clicking on the flag button multiple times doesn't create multiple
error messages on screen at once, but this isn't working - multiple
error messages still appear. Not sure why.
(Fixed, see below)

@codecov-io
Copy link

codecov-io commented Apr 26, 2017

Codecov Report

Merging #374 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #374      +/-   ##
=========================================
+ Coverage   89.39%   89.4%   +<.01%     
=========================================
  Files         121     121              
  Lines        4773    4776       +3     
  Branches      814     815       +1     
=========================================
+ Hits         4267    4270       +3     
  Misses        506     506
Impacted Files Coverage Δ
src/sidebar/components/annotation.js 88.47% <100%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a368baf...cd22ae6. Read the comment docs.

@seanh
Copy link
Contributor Author

seanh commented Apr 26, 2017

This doesn't add a clickable login link or button yet.

@seanh
Copy link
Contributor Author

seanh commented Apr 27, 2017

I am using the preventOpenDuplicates: true option to angular-toastr so
that clicking on the flag button multiple times doesn't create multiple
error messages on screen at once, but this isn't working - multiple
error messages still appear. Not sure why.

I've found the solution to this: preventOpenDuplicates: true needs to be set globally, for all toastr messages, not on a per-message basis. This is easily done but I'll send it as a separate PR. For now I'll remove the setting from this PR.

Improve the error message that's shown to the user when trying to flag
an annotation while logged out.

Instead of showing a "404 Not Found. Either the resource you requested
doesn't exist, or you are not currently authorized to see it." error
from the server, show a friendlier "You must be logged in to report an
annotation" message.

This is done client-side by checking whether the user is logged in when
they click the flag button, and if not showing an error instead of
sending the flag request to the API. This is because the API doesn't
respond with a unique "You must be logged in to flag" error that the
client could depend on, it just returns a 404, which could be for a
number of reasons (e.g. the annotation no longer exists).
@seanh seanh force-pushed the improve-error-when-flagging-when-logged-out branch from 55f2cfb to cd22ae6 Compare April 27, 2017 10:58
@seanh
Copy link
Contributor Author

seanh commented Apr 27, 2017

Done

parts.controller.flag();
assert.calledWith(fakeAnnotationMapper.flagAnnotation,
parts.annotation);
done();
Copy link
Member

Choose a reason for hiding this comment

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

The done callback here is unnecessary since this test is synchronous.

var controller = createDirective().controller;
var err = new Error('500 Server error');
fakeAnnotationMapper.flagAnnotation.returns(Promise.reject(err));
controller.flag();
Copy link
Member

Choose a reason for hiding this comment

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

I note that this was an issue with the existing code, but the setTimeout here could have been avoided if flag return a Promise which resolved once the flagging request had completed.

);
context('when the user is not logged in', function() {
beforeEach(function() {
delete fakeSession.state.userid;
Copy link
Member

@robertknight robertknight May 4, 2017

Choose a reason for hiding this comment

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

Strictly speaking, the userid will be null rather than undefined if the user is not logged in, which is what happens when deleting a property.

@robertknight
Copy link
Member

robertknight commented May 4, 2017

LGTM. One minor note: I would prefer that in future we stick with native promises where possible and try to avoid mixing $q and native promises which have different behaviours.

@robertknight robertknight merged commit 46ba01c into master May 4, 2017
@robertknight robertknight deleted the improve-error-when-flagging-when-logged-out branch May 4, 2017 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants