Built motion from commit 97153652.|2.6.26
[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 _0x4736=['message','Internal\x20Server\x20Error','name','Error','Bad\x20Request','inherits','Forbidden','Not\x20Found','Out\x20Of\x20Interval','code','details','OutOfInterval','Conflict','stack','statusMessage','status','send','exports','../config/logger','api'];(function(_0xaf4f93,_0x3129ce){var _0x15230e=function(_0x537f3c){while(--_0x537f3c){_0xaf4f93['push'](_0xaf4f93['shift']());}};_0x15230e(++_0x3129ce);}(_0x4736,0x12a));var _0x6473=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x4736[_0x3dd15e];return _0x231fd0;};'use strict';var util=require('util');var logger=require(_0x6473('0x0'))(_0x6473('0x1'));var APIError=function(_0x2e7253,_0x5ea330){this[_0x6473('0x2')]=_0x2e7253||_0x6473('0x3');this[_0x6473('0x4')]=_0x5ea330||_0x6473('0x5');util['inherits'](APIError,Error);};var APIBadRequestError=function(_0x355597){this['message']=_0x355597||_0x6473('0x6');this['name']=_0x6473('0x6');util[_0x6473('0x7')](APIBadRequestError,APIError);};var APIForbiddenError=function(_0x473ed5){this['message']=_0x473ed5||_0x6473('0x8');this['name']='Forbidden';util[_0x6473('0x7')](APIForbiddenError,APIError);};var APINotFoundError=function(_0x5f4a71){this['message']=_0x5f4a71||'Entity\x20not\x20found';this[_0x6473('0x4')]=_0x6473('0x9');util['inherits'](APINotFoundError,APIError);};var APIOutOfIntervalError=function(_0x1094d7){this[_0x6473('0x2')]=_0x1094d7||'Message\x20sent\x20outside\x20a\x20valid\x20interval';this['name']=_0x6473('0xa');this[_0x6473('0xb')]=0x193;this[_0x6473('0xc')]={'type':_0x6473('0xd')};util['inherits'](APIOutOfIntervalError,APIError);};var APIConflictError=function(_0x1c70b8){this[_0x6473('0x2')]=_0x1c70b8||'Resource\x20Conflict';this[_0x6473('0x4')]=_0x6473('0xe');util['inherits'](APIBadRequestError,APIError);};function getStatusCode(_0x452cea){switch(_0x452cea){case _0x6473('0x6'):return 0x190;case _0x6473('0x8'),'Out\x20Of\x20Interval':return 0x193;case'Not\x20Found':return 0x194;case _0x6473('0xe'):return 0x199;default:return 0x1f4;}}function getCustomStatusMessage(_0x2ccc8f){if(_0x2ccc8f===_0x6473('0xa'))return _0x2ccc8f;return null;}function handleError(_0x187e80){return function(_0x265548){logger['error'](_0x265548[_0x6473('0xf')]);var _0x576575=getStatusCode(_0x265548[_0x6473('0x4')]);var _0x12b4d5=getCustomStatusMessage(_0x265548['name']);if(_0x265548[_0x6473('0x4')]){delete _0x265548[_0x6473('0x4')];}if(_0x12b4d5){_0x187e80[_0x6473('0x10')]=_0x12b4d5;}return _0x187e80[_0x6473('0x11')](_0x576575)[_0x6473('0x12')](_0x265548);};}module[_0x6473('0x13')]={'APIError':APIError,'APIBadRequestError':APIBadRequestError,'APIForbiddenError':APIForbiddenError,'APINotFoundError':APINotFoundError,'APIOutOfIntervalError':APIOutOfIntervalError,'APIConflict':APIConflictError,'handleError':handleError};