Commit 874fb132 authored by Randall Leeds's avatar Randall Leeds

On save, show a generic error for unavailability

parent fedf587b
...@@ -13,10 +13,14 @@ validate = (value) -> ...@@ -13,10 +13,14 @@ validate = (value) ->
# Return an error message based on a server response. # Return an error message based on a server response.
errorMessage = (reason) -> errorMessage = (reason) ->
message = reason.status + " " + reason.statusText if reason.status is 0
if reason.data.reason message = "Service unreachable."
message = message + ": " + reason.data.reason else
message message = reason.status + " " + reason.statusText
if reason.data.reason
message = message + ": " + reason.data.reason
return message
###* ###*
......
...@@ -412,6 +412,16 @@ describe 'annotation', -> ...@@ -412,6 +412,16 @@ describe 'annotation', ->
window.confirm.returns(false) window.confirm.returns(false)
assert fakeAnnotationMapper.deleteAnnotation.notCalled assert fakeAnnotationMapper.deleteAnnotation.notCalled
it "flashes a generic error if the server cannot be reached", ->
window.confirm.returns(true)
fakeAnnotationMapper.deleteAnnotation.returns(Promise.reject({status: 0}))
controller.delete().then(->
assert fakeFlash.error.calledWith(
"Service unreachable.", "Saving annotation failed")
)
$timeout.flush()
it "flashes an error if the delete fails on the server", -> it "flashes an error if the delete fails on the server", ->
window.confirm.returns(true) window.confirm.returns(true)
fakeAnnotationMapper.deleteAnnotation.returns(Promise.reject({ fakeAnnotationMapper.deleteAnnotation.returns(Promise.reject({
...@@ -448,6 +458,14 @@ describe 'annotation', -> ...@@ -448,6 +458,14 @@ describe 'annotation', ->
assert $rootScope.$emit.calledWith("annotationCreated") assert $rootScope.$emit.calledWith("annotationCreated")
) )
it "flashes a generic error if the server cannot be reached", ->
annotation.$create.returns(Promise.reject({status: 0}))
controller.save().then(->
assert fakeFlash.error.calledWith(
"Service unreachable.", "Saving annotation failed")
)
it "flashes an error if saving the annotation fails on the server", -> it "flashes an error if saving the annotation fails on the server", ->
annotation.$create.returns(Promise.reject({ annotation.$create.returns(Promise.reject({
status: 500, status: 500,
...@@ -474,6 +492,14 @@ describe 'annotation', -> ...@@ -474,6 +492,14 @@ describe 'annotation', ->
controller.action = 'edit' controller.action = 'edit'
annotation.$update = sandbox.stub() annotation.$update = sandbox.stub()
it "flashes a generic error if the server cannot be reached", ->
annotation.$update.returns(Promise.reject({status: 0}))
controller.save().then(->
assert fakeFlash.error.calledWith(
"Service unreachable.", "Saving annotation failed")
)
it "flashes an error if saving the annotation fails on the server", -> it "flashes an error if saving the annotation fails on the server", ->
annotation.$update.returns(Promise.reject({ annotation.$update.returns(Promise.reject({
status: 500, status: 500,
......
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