2ad4f12eff8034173c6bafed0c648d940d1787aa
[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 _0x81f5=['exports','util','../config/logger','api','message','Internal\x20Server\x20Error','name','Bad\x20Request','inherits','Forbidden','Message\x20sent\x20outside\x20a\x20valid\x20interval','Out\x20Of\x20Interval','Resource\x20Conflict','Conflict','error','stack','send'];(function(_0x4db46b,_0xadcb1a){var _0x565be8=function(_0x5d2e50){while(--_0x5d2e50){_0x4db46b['push'](_0x4db46b['shift']());}};_0x565be8(++_0xadcb1a);}(_0x81f5,0xde));var _0x581f=function(_0x4fc9e6,_0xc51915){_0x4fc9e6=_0x4fc9e6-0x0;var _0x551d28=_0x81f5[_0x4fc9e6];return _0x551d28;};'use strict';var util=require(_0x581f('0x0'));var logger=require(_0x581f('0x1'))(_0x581f('0x2'));var APIError=function(_0x32bc7a,_0xcfcce2){this[_0x581f('0x3')]=_0x32bc7a||_0x581f('0x4');this[_0x581f('0x5')]=_0xcfcce2||'Error';util['inherits'](APIError,Error);};var APIBadRequestError=function(_0x2068d3){this[_0x581f('0x3')]=_0x2068d3||'Bad\x20Request';this[_0x581f('0x5')]=_0x581f('0x6');util[_0x581f('0x7')](APIBadRequestError,APIError);};var APIForbiddenError=function(_0x1c2914){this[_0x581f('0x3')]=_0x1c2914||_0x581f('0x8');this[_0x581f('0x5')]=_0x581f('0x8');util[_0x581f('0x7')](APIForbiddenError,APIError);};var APINotFoundError=function(_0x10340d){this[_0x581f('0x3')]=_0x10340d||'Entity\x20not\x20found';this[_0x581f('0x5')]='Not\x20Found';util[_0x581f('0x7')](APINotFoundError,APIError);};var APIOutOfIntervalError=function(_0x3e0de0){this[_0x581f('0x3')]=_0x3e0de0||_0x581f('0x9');this['name']=_0x581f('0xa');this['code']=0x193;this['details']={'type':'OutOfInterval'};util[_0x581f('0x7')](APIOutOfIntervalError,APIError);};var APIConflictError=function(_0x1af694){this['message']=_0x1af694||_0x581f('0xb');this[_0x581f('0x5')]=_0x581f('0xc');util['inherits'](APIBadRequestError,APIError);};function getStatusCode(_0x499d89){switch(_0x499d89){case _0x581f('0x6'):return 0x190;case'Forbidden',_0x581f('0xa'):return 0x193;case'Not\x20Found':return 0x194;case _0x581f('0xc'):return 0x199;default:return 0x1f4;}}function getCustomStatusMessage(_0x4ccf70){if(_0x4ccf70===_0x581f('0xa'))return _0x4ccf70;return null;}function handleError(_0x199928){return function(_0xfa78c0){logger[_0x581f('0xd')](_0xfa78c0[_0x581f('0xe')]);var _0x57ac58=getStatusCode(_0xfa78c0[_0x581f('0x5')]);var _0x217204=getCustomStatusMessage(_0xfa78c0[_0x581f('0x5')]);if(_0xfa78c0[_0x581f('0x5')]){delete _0xfa78c0[_0x581f('0x5')];}if(_0x217204){_0x199928['statusMessage']=_0x217204;}return _0x199928['status'](_0x57ac58)[_0x581f('0xf')](_0xfa78c0);};}module[_0x581f('0x10')]={'APIError':APIError,'APIBadRequestError':APIBadRequestError,'APIForbiddenError':APIForbiddenError,'APINotFoundError':APINotFoundError,'APIOutOfIntervalError':APIOutOfIntervalError,'APIConflict':APIConflictError,'handleError':handleError};