Built motion from commit 3d6333b4.|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 _0x034e=['name','inherits','Not\x20Found','Message\x20sent\x20outside\x20a\x20valid\x20interval','Out\x20Of\x20Interval','code','Resource\x20Conflict','Conflict','error','stack','statusMessage','send','exports','util','api','message','Internal\x20Server\x20Error','Bad\x20Request'];(function(_0x501808,_0x4fd17d){var _0x3f3976=function(_0x37cc24){while(--_0x37cc24){_0x501808['push'](_0x501808['shift']());}};_0x3f3976(++_0x4fd17d);}(_0x034e,0x79));var _0xe034=function(_0x4fdbd3,_0x35fd1a){_0x4fdbd3=_0x4fdbd3-0x0;var _0x50ebf0=_0x034e[_0x4fdbd3];return _0x50ebf0;};'use strict';var util=require(_0xe034('0x0'));var logger=require('../config/logger')(_0xe034('0x1'));var APIError=function(_0x22534d,_0x5554e0){this[_0xe034('0x2')]=_0x22534d||_0xe034('0x3');this['name']=_0x5554e0||'Error';util['inherits'](APIError,Error);};var APIBadRequestError=function(_0x39b8ab){this['message']=_0x39b8ab||_0xe034('0x4');this[_0xe034('0x5')]=_0xe034('0x4');util[_0xe034('0x6')](APIBadRequestError,APIError);};var APIForbiddenError=function(_0x15da93){this[_0xe034('0x2')]=_0x15da93||'Forbidden';this[_0xe034('0x5')]='Forbidden';util[_0xe034('0x6')](APIForbiddenError,APIError);};var APINotFoundError=function(_0x826429){this['message']=_0x826429||'Entity\x20not\x20found';this[_0xe034('0x5')]=_0xe034('0x7');util['inherits'](APINotFoundError,APIError);};var APIOutOfIntervalError=function(_0x48e429){this[_0xe034('0x2')]=_0x48e429||_0xe034('0x8');this[_0xe034('0x5')]=_0xe034('0x9');this[_0xe034('0xa')]=0x193;this['details']={'type':'OutOfInterval'};util['inherits'](APIOutOfIntervalError,APIError);};var APIConflictError=function(_0x4a776b){this['message']=_0x4a776b||_0xe034('0xb');this[_0xe034('0x5')]='Conflict';util[_0xe034('0x6')](APIBadRequestError,APIError);};function getStatusCode(_0x247c26){switch(_0x247c26){case _0xe034('0x4'):return 0x190;case'Forbidden',_0xe034('0x9'):return 0x193;case _0xe034('0x7'):return 0x194;case _0xe034('0xc'):return 0x199;default:return 0x1f4;}}function getCustomStatusMessage(_0x3dae21){if(_0x3dae21===_0xe034('0x9'))return _0x3dae21;return null;}function handleError(_0x5f0aa1){return function(_0x384960){logger[_0xe034('0xd')](_0x384960[_0xe034('0xe')]);var _0x534a61=getStatusCode(_0x384960['name']);var _0x18aeb9=getCustomStatusMessage(_0x384960['name']);if(_0x384960[_0xe034('0x5')]){delete _0x384960[_0xe034('0x5')];}if(_0x18aeb9){_0x5f0aa1[_0xe034('0xf')]=_0x18aeb9;}return _0x5f0aa1['status'](_0x534a61)[_0xe034('0x10')](_0x384960);};}module[_0xe034('0x11')]={'APIError':APIError,'APIBadRequestError':APIBadRequestError,'APIForbiddenError':APIForbiddenError,'APINotFoundError':APINotFoundError,'APIOutOfIntervalError':APIOutOfIntervalError,'APIConflict':APIConflictError,'handleError':handleError};