d36314b8f38d0283390237e0e6bf6e769af95061
[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 _0xe7de=['Bad\x20Request','inherits','Forbidden','Entity\x20not\x20found','Not\x20Found','Message\x20sent\x20outside\x20a\x20valid\x20interval','Out\x20Of\x20Interval','code','details','OutOfInterval','Conflict','stack','statusMessage','status','send','util','../config/logger','api','Internal\x20Server\x20Error','name','Error','message'];(function(_0x2d5805,_0x21954e){var _0x1cae4f=function(_0x53ff24){while(--_0x53ff24){_0x2d5805['push'](_0x2d5805['shift']());}};_0x1cae4f(++_0x21954e);}(_0xe7de,0x1f3));var _0xee7d=function(_0x409907,_0x809671){_0x409907=_0x409907-0x0;var _0x304114=_0xe7de[_0x409907];return _0x304114;};'use strict';var util=require(_0xee7d('0x0'));var logger=require(_0xee7d('0x1'))(_0xee7d('0x2'));var APIError=function(_0x5a98be,_0x9fd7d){this['message']=_0x5a98be||_0xee7d('0x3');this[_0xee7d('0x4')]=_0x9fd7d||_0xee7d('0x5');util['inherits'](APIError,Error);};var APIBadRequestError=function(_0x17c69a){this[_0xee7d('0x6')]=_0x17c69a||_0xee7d('0x7');this['name']=_0xee7d('0x7');util[_0xee7d('0x8')](APIBadRequestError,APIError);};var APIForbiddenError=function(_0x15ed31){this['message']=_0x15ed31||'Forbidden';this['name']=_0xee7d('0x9');util[_0xee7d('0x8')](APIForbiddenError,APIError);};var APINotFoundError=function(_0x3e00b5){this['message']=_0x3e00b5||_0xee7d('0xa');this[_0xee7d('0x4')]=_0xee7d('0xb');util[_0xee7d('0x8')](APINotFoundError,APIError);};var APIOutOfIntervalError=function(_0x3edfe0){this[_0xee7d('0x6')]=_0x3edfe0||_0xee7d('0xc');this[_0xee7d('0x4')]=_0xee7d('0xd');this[_0xee7d('0xe')]=0x193;this[_0xee7d('0xf')]={'type':_0xee7d('0x10')};util[_0xee7d('0x8')](APIOutOfIntervalError,APIError);};var APIConflictError=function(_0x537579){this[_0xee7d('0x6')]=_0x537579||'Resource\x20Conflict';this[_0xee7d('0x4')]=_0xee7d('0x11');util[_0xee7d('0x8')](APIBadRequestError,APIError);};function getStatusCode(_0x3fc4a8){switch(_0x3fc4a8){case _0xee7d('0x7'):return 0x190;case _0xee7d('0x9'),_0xee7d('0xd'):return 0x193;case _0xee7d('0xb'):return 0x194;case'Conflict':return 0x199;default:return 0x1f4;}}function getCustomStatusMessage(_0x1cf9b8){if(_0x1cf9b8==='Out\x20Of\x20Interval')return _0x1cf9b8;return null;}function handleError(_0x2157e5){return function(_0x7992bf){logger['error'](_0x7992bf[_0xee7d('0x12')]);var _0x3c9358=getStatusCode(_0x7992bf[_0xee7d('0x4')]);var _0x1fb450=getCustomStatusMessage(_0x7992bf['name']);if(_0x7992bf[_0xee7d('0x4')]){delete _0x7992bf['name'];}if(_0x1fb450){_0x2157e5[_0xee7d('0x13')]=_0x1fb450;}return _0x2157e5[_0xee7d('0x14')](_0x3c9358)[_0xee7d('0x15')](_0x7992bf);};}module['exports']={'APIError':APIError,'APIBadRequestError':APIBadRequestError,'APIForbiddenError':APIForbiddenError,'APINotFoundError':APINotFoundError,'APIOutOfIntervalError':APIOutOfIntervalError,'APIConflict':APIConflictError,'handleError':handleError};