Fix and improve new errors system

* Fix error property name -> errorName
* showNotyError can handle Backbone error callbacks where jqxhr is second param
* showNotyError correctly shows JSON error message or name
* Add timeout to showNotyError
This commit is contained in:
Scott Erickson 2016-03-03 13:59:17 -08:00
parent eb47e83fb4
commit 47f3223be1
2 changed files with 13 additions and 11 deletions

View file

@ -41,11 +41,13 @@ module.exports.connectionFailure = connectionFailure = ->
)
showErrorModal(html)
module.exports.showNotyNetworkError = (jqxhr) ->
module.exports.showNotyNetworkError = ->
jqxhr = _.find(arguments, 'promise') # handles jquery or backbone network error (jqxhr is first or second parameter)
noty({
text: jqxhr.responseText or 'Unknown error'
text: jqxhr.responseJSON?.message or jqxhr.responseJSON?.errorName or 'Unknown error'
layout: 'topCenter'
type: 'error'
timeout: 5000
killer: false,
dismissQueue: true
})

View file

@ -106,36 +106,36 @@ module.exports.NetworkError = NetworkError
module.exports.Unauthorized = class Unauthorized extends NetworkError
code: 401
name: 'Unauthorized'
errorName: 'Unauthorized'
module.exports.Forbidden = class Forbidden extends NetworkError
code: 403
name: 'Forbidden'
errorName: 'Forbidden'
module.exports.NotFound = class NotFound extends NetworkError
code: 404
name: 'Not Found'
errorName: 'Not Found'
module.exports.MethodNotAllowed = class MethodNotAllowed extends NetworkError
code: 405
name: 'Method Not Allowed'
errorName: 'Method Not Allowed'
module.exports.RequestTimeout = class RequestTimeout extends NetworkError
code: 407
name: 'Request Timeout'
errorName: 'Request Timeout'
module.exports.Conflict = class Conflict extends NetworkError
code: 409
name: 'Conflict'
errorName: 'Conflict'
module.exports.UnprocessableEntity = class UnprocessableEntity extends NetworkError
code: 422
name: 'Unprocessable Entity'
errorName: 'Unprocessable Entity'
module.exports.InternalServerError = class InternalServerError extends NetworkError
code: 500
name: 'Internal Server Error'
errorName: 'Internal Server Error'
module.exports.GatewayTimeout = class GatewayTimeout extends NetworkError
code: 504
name: 'Gateway Timeout'
errorName: 'Gateway Timeout'