32077291e6ade98c70c83e55c5443aed0400948b
[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 _0xd2fc=['Bad\x20Request','name','Forbidden','Not\x20Found','Message\x20sent\x20outside\x20a\x20valid\x20interval','code','details','Resource\x20Conflict','Conflict','Out\x20Of\x20Interval','send','api','message','Internal\x20Server\x20Error','Error','inherits'];(function(_0x221a60,_0x332552){var _0x26072a=function(_0x47b9a6){while(--_0x47b9a6){_0x221a60['push'](_0x221a60['shift']());}};_0x26072a(++_0x332552);}(_0xd2fc,0x16b));var _0xcd2f=function(_0x49ff7b,_0x2a784f){_0x49ff7b=_0x49ff7b-0x0;var _0x4cef9c=_0xd2fc[_0x49ff7b];return _0x4cef9c;};'use strict';var util=require('util');var logger=require('../config/logger')(_0xcd2f('0x0'));var APIError=function(_0x4cfbc7,_0xd6d987){this[_0xcd2f('0x1')]=_0x4cfbc7||_0xcd2f('0x2');this['name']=_0xd6d987||_0xcd2f('0x3');util[_0xcd2f('0x4')](APIError,Error);};var APIBadRequestError=function(_0x50dd91){this[_0xcd2f('0x1')]=_0x50dd91||_0xcd2f('0x5');this[_0xcd2f('0x6')]=_0xcd2f('0x5');util[_0xcd2f('0x4')](APIBadRequestError,APIError);};var APIForbiddenError=function(_0x1cca4b){this[_0xcd2f('0x1')]=_0x1cca4b||_0xcd2f('0x7');this[_0xcd2f('0x6')]=_0xcd2f('0x7');util[_0xcd2f('0x4')](APIForbiddenError,APIError);};var APINotFoundError=function(_0x1a8a08){this[_0xcd2f('0x1')]=_0x1a8a08||'Entity\x20not\x20found';this['name']=_0xcd2f('0x8');util['inherits'](APINotFoundError,APIError);};var APIOutOfIntervalError=function(_0x2a81b9){this['message']=_0x2a81b9||_0xcd2f('0x9');this[_0xcd2f('0x6')]='Out\x20Of\x20Interval';this[_0xcd2f('0xa')]=0x193;this[_0xcd2f('0xb')]={'type':'OutOfInterval'};util['inherits'](APIOutOfIntervalError,APIError);};var APIConflictError=function(_0x57be0a){this[_0xcd2f('0x1')]=_0x57be0a||_0xcd2f('0xc');this[_0xcd2f('0x6')]=_0xcd2f('0xd');util[_0xcd2f('0x4')](APIBadRequestError,APIError);};function getStatusCode(_0x3eede6){switch(_0x3eede6){case'Bad\x20Request':return 0x190;case _0xcd2f('0x7'),_0xcd2f('0xe'):return 0x193;case _0xcd2f('0x8'):return 0x194;case'Conflict':return 0x199;default:return 0x1f4;}}function getCustomStatusMessage(_0x2cabbf){if(_0x2cabbf===_0xcd2f('0xe'))return _0x2cabbf;return null;}function handleError(_0x492547){return function(_0x3f9cfd){logger['error'](_0x3f9cfd['stack']);var _0x140840=getStatusCode(_0x3f9cfd['name']);var _0x366e22=getCustomStatusMessage(_0x3f9cfd[_0xcd2f('0x6')]);if(_0x3f9cfd['name']){delete _0x3f9cfd['name'];}if(_0x366e22){_0x492547['statusMessage']=_0x366e22;}return _0x492547['status'](_0x140840)[_0xcd2f('0xf')](_0x3f9cfd);};}module['exports']={'APIError':APIError,'APIBadRequestError':APIBadRequestError,'APIForbiddenError':APIForbiddenError,'APINotFoundError':APINotFoundError,'APIOutOfIntervalError':APIOutOfIntervalError,'APIConflict':APIConflictError,'handleError':handleError};