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) ->
# Return an error message based on a server response.
errorMessage = (reason) ->
message = reason.status + " " + reason.statusText
if reason.data.reason
message = message + ": " + reason.data.reason
message
if reason.status is 0
message = "Service unreachable."
else
message = reason.status + " " + reason.statusText
if reason.data.reason
message = message + ": " + reason.data.reason
return message
###*
......
......@@ -412,6 +412,16 @@ describe 'annotation', ->
window.confirm.returns(false)
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", ->
window.confirm.returns(true)
fakeAnnotationMapper.deleteAnnotation.returns(Promise.reject({
......@@ -448,6 +458,14 @@ describe 'annotation', ->
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", ->
annotation.$create.returns(Promise.reject({
status: 500,
......@@ -474,6 +492,14 @@ describe 'annotation', ->
controller.action = 'edit'
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", ->
annotation.$update.returns(Promise.reject({
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