8e7c695c29c85972dab0d447f3dfddaf36aedcbe
[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 _0x4012=['send','exports','../config/logger','api','message','Internal\x20Server\x20Error','name','Error','inherits','Bad\x20Request','Forbidden','Entity\x20not\x20found','Out\x20Of\x20Interval','details','OutOfInterval','Resource\x20Conflict','Conflict','Not\x20Found','error','stack','statusMessage','status'];(function(_0x6cc414,_0x279438){var _0x100fcc=function(_0x6f20e4){while(--_0x6f20e4){_0x6cc414['push'](_0x6cc414['shift']());}};_0x100fcc(++_0x279438);}(_0x4012,0x1e6));var _0x2401=function(_0x554496,_0x27e942){_0x554496=_0x554496-0x0;var _0x173f5a=_0x4012[_0x554496];return _0x173f5a;};'use strict';var util=require('util');var logger=require(_0x2401('0x0'))(_0x2401('0x1'));var APIError=function(_0x317f3d,_0x3e454b){this[_0x2401('0x2')]=_0x317f3d||_0x2401('0x3');this[_0x2401('0x4')]=_0x3e454b||_0x2401('0x5');util[_0x2401('0x6')](APIError,Error);};var APIBadRequestError=function(_0x53864a){this[_0x2401('0x2')]=_0x53864a||_0x2401('0x7');this['name']='Bad\x20Request';util[_0x2401('0x6')](APIBadRequestError,APIError);};var APIForbiddenError=function(_0x58b96f){this[_0x2401('0x2')]=_0x58b96f||_0x2401('0x8');this[_0x2401('0x4')]=_0x2401('0x8');util[_0x2401('0x6')](APIForbiddenError,APIError);};var APINotFoundError=function(_0x181c91){this[_0x2401('0x2')]=_0x181c91||_0x2401('0x9');this[_0x2401('0x4')]='Not\x20Found';util['inherits'](APINotFoundError,APIError);};var APIOutOfIntervalError=function(_0xc139dd){this[_0x2401('0x2')]=_0xc139dd||'Message\x20sent\x20outside\x20a\x20valid\x20interval';this['name']=_0x2401('0xa');this['code']=0x193;this[_0x2401('0xb')]={'type':_0x2401('0xc')};util['inherits'](APIOutOfIntervalError,APIError);};var APIConflictError=function(_0x3f6e1c){this[_0x2401('0x2')]=_0x3f6e1c||_0x2401('0xd');this['name']=_0x2401('0xe');util[_0x2401('0x6')](APIBadRequestError,APIError);};function getStatusCode(_0x19949b){switch(_0x19949b){case _0x2401('0x7'):return 0x190;case'Forbidden','Out\x20Of\x20Interval':return 0x193;case _0x2401('0xf'):return 0x194;case _0x2401('0xe'):return 0x199;default:return 0x1f4;}}function getCustomStatusMessage(_0xfe15dc){if(_0xfe15dc===_0x2401('0xa'))return _0xfe15dc;return null;}function handleError(_0x138718){return function(_0x21c8e4){logger[_0x2401('0x10')](_0x21c8e4[_0x2401('0x11')]);var _0xa7de34=getStatusCode(_0x21c8e4[_0x2401('0x4')]);var _0x450925=getCustomStatusMessage(_0x21c8e4[_0x2401('0x4')]);if(_0x21c8e4[_0x2401('0x4')]){delete _0x21c8e4[_0x2401('0x4')];}if(_0x450925){_0x138718[_0x2401('0x12')]=_0x450925;}return _0x138718[_0x2401('0x13')](_0xa7de34)[_0x2401('0x14')](_0x21c8e4);};}module[_0x2401('0x15')]={'APIError':APIError,'APIBadRequestError':APIBadRequestError,'APIForbiddenError':APIForbiddenError,'APINotFoundError':APINotFoundError,'APIOutOfIntervalError':APIOutOfIntervalError,'APIConflict':APIConflictError,'handleError':handleError};