Built motion from commit ecb45b58.|2.6.31
[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 _0x4e20=['Not\x20Found','Out\x20Of\x20Interval','code','details','OutOfInterval','Conflict','error','statusMessage','send','exports','util','../config/logger','api','message','Internal\x20Server\x20Error','Error','Bad\x20Request','inherits','Forbidden','name'];(function(_0x4bfb8a,_0x5bd7e9){var _0x31826e=function(_0x405e88){while(--_0x405e88){_0x4bfb8a['push'](_0x4bfb8a['shift']());}};_0x31826e(++_0x5bd7e9);}(_0x4e20,0xfa));var _0x04e2=function(_0x2283dc,_0x2fcfc5){_0x2283dc=_0x2283dc-0x0;var _0x16db90=_0x4e20[_0x2283dc];return _0x16db90;};'use strict';var util=require(_0x04e2('0x0'));var logger=require(_0x04e2('0x1'))(_0x04e2('0x2'));var APIError=function(_0x175a24,_0x19884d){this[_0x04e2('0x3')]=_0x175a24||_0x04e2('0x4');this['name']=_0x19884d||_0x04e2('0x5');util['inherits'](APIError,Error);};var APIBadRequestError=function(_0xf7c61d){this['message']=_0xf7c61d||'Bad\x20Request';this['name']=_0x04e2('0x6');util[_0x04e2('0x7')](APIBadRequestError,APIError);};var APIForbiddenError=function(_0x5dc50c){this[_0x04e2('0x3')]=_0x5dc50c||_0x04e2('0x8');this[_0x04e2('0x9')]='Forbidden';util[_0x04e2('0x7')](APIForbiddenError,APIError);};var APINotFoundError=function(_0x294954){this[_0x04e2('0x3')]=_0x294954||'Entity\x20not\x20found';this[_0x04e2('0x9')]=_0x04e2('0xa');util['inherits'](APINotFoundError,APIError);};var APIOutOfIntervalError=function(_0x32aa5c){this[_0x04e2('0x3')]=_0x32aa5c||'Message\x20sent\x20outside\x20a\x20valid\x20interval';this[_0x04e2('0x9')]=_0x04e2('0xb');this[_0x04e2('0xc')]=0x193;this[_0x04e2('0xd')]={'type':_0x04e2('0xe')};util[_0x04e2('0x7')](APIOutOfIntervalError,APIError);};var APIConflictError=function(_0x1f5ce7){this[_0x04e2('0x3')]=_0x1f5ce7||'Resource\x20Conflict';this[_0x04e2('0x9')]=_0x04e2('0xf');util['inherits'](APIBadRequestError,APIError);};function getStatusCode(_0x4df666){switch(_0x4df666){case'Bad\x20Request':return 0x190;case _0x04e2('0x8'),_0x04e2('0xb'):return 0x193;case _0x04e2('0xa'):return 0x194;case _0x04e2('0xf'):return 0x199;default:return 0x1f4;}}function getCustomStatusMessage(_0x43ae9d){if(_0x43ae9d===_0x04e2('0xb'))return _0x43ae9d;return null;}function handleError(_0x4ed37b){return function(_0x5db68){logger[_0x04e2('0x10')](_0x5db68['stack']);var _0x1d1658=getStatusCode(_0x5db68[_0x04e2('0x9')]);var _0x2694a5=getCustomStatusMessage(_0x5db68['name']);if(_0x5db68[_0x04e2('0x9')]){delete _0x5db68['name'];}if(_0x2694a5){_0x4ed37b[_0x04e2('0x11')]=_0x2694a5;}return _0x4ed37b['status'](_0x1d1658)[_0x04e2('0x12')](_0x5db68);};}module[_0x04e2('0x13')]={'APIError':APIError,'APIBadRequestError':APIBadRequestError,'APIForbiddenError':APIForbiddenError,'APINotFoundError':APINotFoundError,'APIOutOfIntervalError':APIOutOfIntervalError,'APIConflict':APIConflictError,'handleError':handleError};