Commit cb7c1a7c authored by Robert Knight's avatar Robert Knight

Fix error in session.js when an /app request fails

When a request to the session endpoint fails with a network
error, avoid trying to parse the response in process()
parent bf029587
...@@ -154,8 +154,11 @@ function session($http, $resource, $rootScope, flash, raven, settings) { ...@@ -154,8 +154,11 @@ function session($http, $resource, $rootScope, flash, raven, settings) {
return model; return model;
}; };
function process(data) { function process(data, headersGetter, status) {
// Parse as json if (status < 200) {
return;
}
data = angular.fromJson(data); data = angular.fromJson(data);
// Lift response data // Lift response data
......
"use strict"; "use strict";
var mock = angular.mock; var angular = require('angular');
var events = require('../events'); var events = require('../events');
var mock = angular.mock;
describe('h:session', function () { describe('h:session', function () {
var $httpBackend; var $httpBackend;
var $rootScope; var $rootScope;
var fakeFlash; var fakeFlash;
var fakeRaven; var fakeRaven;
var fakeXsrf;
var sandbox; var sandbox;
var session; var session;
...@@ -50,7 +51,7 @@ describe('h:session', function () { ...@@ -50,7 +51,7 @@ describe('h:session', function () {
// There's little point testing every single route here, as they're // There's little point testing every single route here, as they're
// declarative and ultimately we'd be testing ngResource. // declarative and ultimately we'd be testing ngResource.
describe('.login()', function () { describe('#login()', function () {
var url = 'https://test.hypothes.is/app?__formid__=login'; var url = 'https://test.hypothes.is/app?__formid__=login';
it('should send an HTTP POST to the action', function () { it('should send an HTTP POST to the action', function () {
...@@ -129,7 +130,7 @@ describe('h:session', function () { ...@@ -129,7 +130,7 @@ describe('h:session', function () {
}); });
}); });
describe('.load()', function () { describe('#load()', function () {
var url = 'https://test.hypothes.is/app'; var url = 'https://test.hypothes.is/app';
it('should fetch the session data', function () { it('should fetch the session data', function () {
...@@ -157,9 +158,15 @@ describe('h:session', function () { ...@@ -157,9 +158,15 @@ describe('h:session', function () {
session.load(); session.load();
$httpBackend.flush(); $httpBackend.flush();
}); });
it('should tolerate failed requests', function () {
$httpBackend.expectGET(url).respond(-1, null);
session.load();
$httpBackend.flush();
});
}); });
describe('.update()', function () { describe('#update()', function () {
it('broadcasts SESSION_CHANGED when the session changes', function () { it('broadcasts SESSION_CHANGED when the session changes', function () {
var sessionChangeCallback = sinon.stub(); var sessionChangeCallback = sinon.stub();
...@@ -220,7 +227,7 @@ describe('h:session', function () { ...@@ -220,7 +227,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'; var url = 'https://test.hypothes.is/app/dismiss_sidebar_tutorial';
it('disables the tutorial for the user', function () { it('disables the tutorial for the user', function () {
$httpBackend.expectPOST(url).respond({}); $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