mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-02 22:17:03 +03:00
Set response ErrorCode as iError for easier fetch error handling
This commit is contained in:
parent
a46c0c3b21
commit
11fd6736bb
24 changed files with 145 additions and 253 deletions
|
|
@ -77,6 +77,9 @@ export const SaveSettingsStep = {
|
|||
* @enum {number}
|
||||
*/
|
||||
export const Notification = {
|
||||
RequestError: 1,
|
||||
RequestAborted: 2,
|
||||
|
||||
InvalidToken: 101,
|
||||
AuthError: 102,
|
||||
ConnectionError: 104,
|
||||
|
|
|
|||
|
|
@ -92,29 +92,17 @@ function getNotificationMessage(code) {
|
|||
* @param {*=} defCode = null
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getNotification(code, message = '', defCode = null) {
|
||||
export function getNotification(code, message = '', defCode = 0) {
|
||||
code = parseInt(code, 10) || 0;
|
||||
if (Notification.ClientViewError === code && message) {
|
||||
return message;
|
||||
}
|
||||
|
||||
defCode = defCode ? parseInt(defCode, 10) || 0 : 0;
|
||||
return getNotificationMessage(code)
|
||||
|| getNotificationMessage(defCode)
|
||||
|| getNotificationMessage(parseInt(defCode, 10))
|
||||
|| '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} response
|
||||
* @param {number} defCode = Notification.UnknownNotification
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getNotificationFromResponse(response, defCode = Notification.UnknownNotification) {
|
||||
return response && response.ErrorCode
|
||||
? getNotification(parseInt(response.ErrorCode, 10) || defCode, response.ErrorMessage || '')
|
||||
: getNotification(defCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} code
|
||||
* @returns {string}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue