265959cb130ee496db7f285c979a6904b316a18d
[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 _0xa9e0=['message','name','Error','inherits','Bad\x20Request','Entity\x20not\x20found','Forbidden','OutOfInterval','Not\x20Found','status','send','util','../config/logger','api'];(function(_0x2ef7ed,_0x45a9c3){var _0x1a83c7=function(_0x1ed2e5){while(--_0x1ed2e5){_0x2ef7ed['push'](_0x2ef7ed['shift']());}};_0x1a83c7(++_0x45a9c3);}(_0xa9e0,0x123));var _0x0a9e=function(_0x102e37,_0x14a181){_0x102e37=_0x102e37-0x0;var _0x35a07c=_0xa9e0[_0x102e37];return _0x35a07c;};'use strict';var util=require(_0x0a9e('0x0'));var logger=require(_0x0a9e('0x1'))(_0x0a9e('0x2'));var APIError=function(_0x5dd881,_0x550fbc){this[_0x0a9e('0x3')]=_0x5dd881||'Internal\x20Server\x20Error';this[_0x0a9e('0x4')]=_0x550fbc||_0x0a9e('0x5');util[_0x0a9e('0x6')](APIError,Error);};var APIBadRequestError=function(_0x991246){this[_0x0a9e('0x3')]=_0x991246||'Bad\x20Request';this[_0x0a9e('0x4')]=_0x0a9e('0x7');util[_0x0a9e('0x6')](APIBadRequestError,APIError);};var APINotFoundError=function(_0x5f41ea){this['message']=_0x5f41ea||_0x0a9e('0x8');this['name']='Not\x20Found';util[_0x0a9e('0x6')](APINotFoundError,APIError);};function getStatusCode(_0xf81284){switch(_0xf81284){case _0x0a9e('0x7'):return 0x190;case _0x0a9e('0x9'),_0x0a9e('0xa'):return 0x193;case _0x0a9e('0xb'):return 0x194;default:return 0x1f4;}}function handleError(_0x4a4c56){return function(_0x50dfb2){logger['error'](_0x50dfb2['stack']);var _0x273d4d=getStatusCode(_0x50dfb2[_0x0a9e('0x4')]);if(_0x50dfb2[_0x0a9e('0x4')])delete _0x50dfb2[_0x0a9e('0x4')];return _0x4a4c56[_0x0a9e('0xc')](_0x273d4d)[_0x0a9e('0xd')](_0x50dfb2);};}module['exports']={'APIError':APIError,'APIBadRequestError':APIBadRequestError,'APINotFoundError':APINotFoundError,'handleError':handleError};