Commit 02010ce2 authored by Christof Dorner's avatar Christof Dorner

Merge pull request #3210 from hypothesis/check-session-response

 Fix error in session.js when an /app request fails 
parents 15d6d3fb 637c7d8b
......@@ -28,30 +28,33 @@ if (settings.raven) {
var mail = require('./vendor/jwz');
var streamer = require('./streamer');
var resolve =
// Ensure that we have available a) the current authenticated userid, and b)
// the list of user groups.
{
sessionState: ['session', function (session) { return session.load(); }],
store: ['store', function (store) { return store.$promise; }],
streamer: streamer.connect,
threading: [
'annotationMapper', 'drafts', 'threading',
function (annotationMapper, drafts, threading) {
// Unload all the annotations
annotationMapper.unloadAnnotations(threading.annotationList());
// Reset the threading root
threading.createIdTable([]);
threading.root = mail.messageContainer();
// Reload all new, unsaved annotations
threading.thread(drafts.unsaved());
return threading;
}
]
};
// Fetch external state that the app needs before it can run. This includes the
// authenticated user state, the API endpoint URLs and WebSocket connection.
var resolve = {
// @ngInject
sessionState: function (session) {
return session.load();
},
// @ngInject
store: function (store) {
return store.$promise;
},
streamer: streamer.connect,
// @ngInject
threading: function (annotationMapper, drafts, threading) {
// Unload all the annotations
annotationMapper.unloadAnnotations(threading.annotationList());
// Reset the threading root
threading.createIdTable([]);
threading.root = mail.messageContainer();
// Reload all new, unsaved annotations
threading.thread(drafts.unsaved());
return threading;
},
};
// @ngInject
function configureLocation($locationProvider) {
......
......@@ -154,8 +154,11 @@ function session($http, $resource, $rootScope, flash, raven, settings) {
return model;
};
function process(data) {
// Parse as json
function process(data, headersGetter, status) {
if (status < 200 || status >= 500) {
return;
}
data = angular.fromJson(data);
// Lift response data
......
"use strict";
var mock = angular.mock;
var angular = require('angular');
var events = require('../events');
var mock = angular.mock;
describe('h:session', function () {
var $httpBackend;
var $rootScope;
var fakeFlash;
var fakeRaven;
var fakeXsrf;
var sandbox;
var session;
......@@ -50,7 +51,7 @@ describe('h:session', function () {
// There's little point testing every single route here, as they're
// declarative and ultimately we'd be testing ngResource.
describe('.login()', function () {
describe('#login()', function () {
var url = 'https://test.hypothes.is/app?__formid__=login';
it('should send an HTTP POST to the action', function () {
......@@ -129,7 +130,7 @@ describe('h:session', function () {
});
});
describe('.load()', function () {
describe('#load()', function () {
var url = 'https://test.hypothes.is/app';
it('should fetch the session data', function () {
......@@ -157,9 +158,25 @@ describe('h:session', function () {
session.load();
$httpBackend.flush();
});
var failedRequestCases = [{
status: -1,
body: null,
},{
status: 504,
body: 'Gateway Timeout',
}];
failedRequestCases.forEach(function (testCase) {
it('should tolerate failed requests', function () {
$httpBackend.expectGET(url).respond(testCase.status, testCase.body);
session.load();
$httpBackend.flush();
});
});
});
describe('.update()', function () {
describe('#update()', function () {
it('broadcasts SESSION_CHANGED when the session changes', function () {
var sessionChangeCallback = sinon.stub();
......@@ -220,7 +237,7 @@ describe('h:session', function () {
});
});
describe('.dismiss_sidebar_tutorial()', function () {
describe('#dismiss_sidebar_tutorial()', function () {
var url = 'https://test.hypothes.is/app/dismiss_sidebar_tutorial';
it('disables the tutorial for the user', function () {
$httpBackend.expectPOST(url).respond({});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment