32dfe34a91ee7b715566a4ed73aad5245464a95e
[motion2.git] / server / errors / api.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x1d1e=['Resource\x20Conflict','Conflict','statusMessage','send','exports','api','message','Internal\x20Server\x20Error','name','Error','inherits','Bad\x20Request','Forbidden','Entity\x20not\x20found','Not\x20Found','Message\x20sent\x20outside\x20a\x20valid\x20interval','Out\x20Of\x20Interval','code','OutOfInterval'];(function(_0x53ea86,_0x2e705f){var _0x16d7d3=function(_0x4b3771){while(--_0x4b3771){_0x53ea86['push'](_0x53ea86['shift']());}};_0x16d7d3(++_0x2e705f);}(_0x1d1e,0xd6));var _0xe1d1=function(_0x2264b7,_0x5a3536){_0x2264b7=_0x2264b7-0x0;var _0x22680e=_0x1d1e[_0x2264b7];return _0x22680e;};'use strict';var util=require('util');var logger=require('../config/logger')(_0xe1d1('0x0'));var APIError=function(_0x339d3f,_0x49e9e2){this[_0xe1d1('0x1')]=_0x339d3f||_0xe1d1('0x2');this[_0xe1d1('0x3')]=_0x49e9e2||_0xe1d1('0x4');util[_0xe1d1('0x5')](APIError,Error);};var APIBadRequestError=function(_0x238b02){this[_0xe1d1('0x1')]=_0x238b02||'Bad\x20Request';this[_0xe1d1('0x3')]=_0xe1d1('0x6');util[_0xe1d1('0x5')](APIBadRequestError,APIError);};var APIForbiddenError=function(_0x365c97){this[_0xe1d1('0x1')]=_0x365c97||_0xe1d1('0x7');this['name']=_0xe1d1('0x7');util['inherits'](APIForbiddenError,APIError);};var APINotFoundError=function(_0x490614){this['message']=_0x490614||_0xe1d1('0x8');this[_0xe1d1('0x3')]=_0xe1d1('0x9');util['inherits'](APINotFoundError,APIError);};var APIOutOfIntervalError=function(_0x4d4ec6){this[_0xe1d1('0x1')]=_0x4d4ec6||_0xe1d1('0xa');this[_0xe1d1('0x3')]=_0xe1d1('0xb');this[_0xe1d1('0xc')]=0x193;this['details']={'type':_0xe1d1('0xd')};util[_0xe1d1('0x5')](APIOutOfIntervalError,APIError);};var APIConflictError=function(_0x16e2f2){this[_0xe1d1('0x1')]=_0x16e2f2||_0xe1d1('0xe');this[_0xe1d1('0x3')]=_0xe1d1('0xf');util[_0xe1d1('0x5')](APIBadRequestError,APIError);};function getStatusCode(_0x475cca){switch(_0x475cca){case _0xe1d1('0x6'):return 0x190;case _0xe1d1('0x7'),_0xe1d1('0xb'):return 0x193;case _0xe1d1('0x9'):return 0x194;case _0xe1d1('0xf'):return 0x199;default:return 0x1f4;}}function getCustomStatusMessage(_0x572c72){if(_0x572c72==='Out\x20Of\x20Interval')return _0x572c72;return null;}function handleError(_0xa53c06){return function(_0x4cce8f){logger['error'](_0x4cce8f['stack']);var _0x37cdb9=getStatusCode(_0x4cce8f[_0xe1d1('0x3')]);var _0x420643=getCustomStatusMessage(_0x4cce8f['name']);if(_0x4cce8f[_0xe1d1('0x3')]){delete _0x4cce8f[_0xe1d1('0x3')];}if(_0x420643){_0xa53c06[_0xe1d1('0x10')]=_0x420643;}return _0xa53c06['status'](_0x37cdb9)[_0xe1d1('0x11')](_0x4cce8f);};}module[_0xe1d1('0x12')]={'APIError':APIError,'APIBadRequestError':APIBadRequestError,'APIForbiddenError':APIForbiddenError,'APINotFoundError':APINotFoundError,'APIOutOfIntervalError':APIOutOfIntervalError,'APIConflict':APIConflictError,'handleError':handleError};