From 47f3223be1948204c28bda17eba6a88b584db02f Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Thu, 3 Mar 2016 13:59:17 -0800 Subject: [PATCH] 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 --- app/core/errors.coffee | 6 ++++-- server/commons/errors.coffee | 18 +++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/core/errors.coffee b/app/core/errors.coffee index 50427d809..4ed05cf9b 100644 --- a/app/core/errors.coffee +++ b/app/core/errors.coffee @@ -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 }) diff --git a/server/commons/errors.coffee b/server/commons/errors.coffee index 874c17880..5571aed0f 100644 --- a/server/commons/errors.coffee +++ b/server/commons/errors.coffee @@ -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'