d4974caa9a47b28c058f1a3378e4f9bcb637cc17
[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 _0x2dfe=['Error','inherits','Bad\x20Request','Forbidden','Entity\x20not\x20found','Not\x20Found','Message\x20sent\x20outside\x20a\x20valid\x20interval','code','details','OutOfInterval','Conflict','Out\x20Of\x20Interval','error','stack','statusMessage','status','send','exports','../config/logger','message','Internal\x20Server\x20Error','name'];(function(_0x336d54,_0x4cb876){var _0x571a8d=function(_0x3746f6){while(--_0x3746f6){_0x336d54['push'](_0x336d54['shift']());}};_0x571a8d(++_0x4cb876);}(_0x2dfe,0x15c));var _0xe2df=function(_0x144ae9,_0x4f551f){_0x144ae9=_0x144ae9-0x0;var _0x2bae3d=_0x2dfe[_0x144ae9];return _0x2bae3d;};'use strict';var util=require('util');var logger=require(_0xe2df('0x0'))('api');var APIError=function(_0x5180de,_0xb57227){this[_0xe2df('0x1')]=_0x5180de||_0xe2df('0x2');this[_0xe2df('0x3')]=_0xb57227||_0xe2df('0x4');util[_0xe2df('0x5')](APIError,Error);};var APIBadRequestError=function(_0x3ec5b3){this[_0xe2df('0x1')]=_0x3ec5b3||_0xe2df('0x6');this[_0xe2df('0x3')]='Bad\x20Request';util['inherits'](APIBadRequestError,APIError);};var APIForbiddenError=function(_0x453d8d){this[_0xe2df('0x1')]=_0x453d8d||'Forbidden';this[_0xe2df('0x3')]=_0xe2df('0x7');util[_0xe2df('0x5')](APIForbiddenError,APIError);};var APINotFoundError=function(_0x41a903){this[_0xe2df('0x1')]=_0x41a903||_0xe2df('0x8');this[_0xe2df('0x3')]=_0xe2df('0x9');util[_0xe2df('0x5')](APINotFoundError,APIError);};var APIOutOfIntervalError=function(_0x5c2e7b){this[_0xe2df('0x1')]=_0x5c2e7b||_0xe2df('0xa');this[_0xe2df('0x3')]='Out\x20Of\x20Interval';this[_0xe2df('0xb')]=0x193;this[_0xe2df('0xc')]={'type':_0xe2df('0xd')};util[_0xe2df('0x5')](APIOutOfIntervalError,APIError);};var APIConflictError=function(_0x47c0f2){this['message']=_0x47c0f2||'Resource\x20Conflict';this['name']=_0xe2df('0xe');util[_0xe2df('0x5')](APIBadRequestError,APIError);};function getStatusCode(_0x30d542){switch(_0x30d542){case _0xe2df('0x6'):return 0x190;case _0xe2df('0x7'),_0xe2df('0xf'):return 0x193;case _0xe2df('0x9'):return 0x194;case _0xe2df('0xe'):return 0x199;default:return 0x1f4;}}function getCustomStatusMessage(_0x229347){if(_0x229347===_0xe2df('0xf'))return _0x229347;return null;}function handleError(_0x140de1){return function(_0x2c3af2){logger[_0xe2df('0x10')](_0x2c3af2[_0xe2df('0x11')]);var _0x777a93=getStatusCode(_0x2c3af2['name']);var _0x471a32=getCustomStatusMessage(_0x2c3af2[_0xe2df('0x3')]);if(_0x2c3af2[_0xe2df('0x3')]){delete _0x2c3af2[_0xe2df('0x3')];}if(_0x471a32){_0x140de1[_0xe2df('0x12')]=_0x471a32;}return _0x140de1[_0xe2df('0x13')](_0x777a93)[_0xe2df('0x14')](_0x2c3af2);};}module[_0xe2df('0x15')]={'APIError':APIError,'APIBadRequestError':APIBadRequestError,'APIForbiddenError':APIForbiddenError,'APINotFoundError':APINotFoundError,'APIOutOfIntervalError':APIOutOfIntervalError,'APIConflict':APIConflictError,'handleError':handleError};