diff --git a/packages/constants/README.md b/packages/constants/README.md index b0799aab740a46bc7082b8141a1e002d782c5be6..6ba01ce2192e2defcb59f14e27b671ab39d61b18 100755 --- a/packages/constants/README.md +++ b/packages/constants/README.md @@ -85,8 +85,6 @@ Please consult the detail break down below. - RETURN_AS_ENUM - NO_ERROR_MSG - NO_STATUS_CODE -- INIT_CLIENT_PROP_KEY -- INIT_CONTRACT_PROP_KEY - SUCCESS_STATUS - UNAUTHORIZED_STATUS - FORBIDDEN_STATUS @@ -136,6 +134,7 @@ Please consult the detail break down below. - WS_OPT_PROP_KEY - CONTRACT_PROP_KEY - TOKEN_PROP_KEY +- INIT_CLIENT_PROP_KEY - INIT_CONTRACT_PROP_KEY - CONTENT_TYPE_PROP_KEY - RETURN_AS_PROP_KEY diff --git a/packages/constants/base.js b/packages/constants/base.js index 65a6d698600967569f6376bf008f94479de88776..f978c5c780345e6c21d53b2056115d4894ea8b28 100644 --- a/packages/constants/base.js +++ b/packages/constants/base.js @@ -115,12 +115,6 @@ export const RETURN_AS_ENUM = [ export const NO_ERROR_MSG = 'No message' export const NO_STATUS_CODE = -1 -// this are property keys used in the configuration options -// and re-use elsewhere -export const INIT_CLIENT_PROP_KEY = 'nodeClient' -export const INIT_CONTRACT_PROP_KEY = 'initContract' - - // status export const SUCCESS_STATUS = 200 export const UNAUTHORIZED_STATUS = 401 diff --git a/packages/constants/browser.js b/packages/constants/browser.js index c1c21552d88e2b4c253de0b9cdcff10a441e240a..896b5bdb35cc21a61375189aa3d4e7e57a7a0112 100644 --- a/packages/constants/browser.js +++ b/packages/constants/browser.js @@ -86,8 +86,6 @@ var jsonqlConstants = { ], "NO_ERROR_MSG": "No message", "NO_STATUS_CODE": -1, - "INIT_CLIENT_PROP_KEY": "nodeClient", - "INIT_CONTRACT_PROP_KEY": "initContract", "SUCCESS_STATUS": 200, "UNAUTHORIZED_STATUS": 401, "FORBIDDEN_STATUS": 403, @@ -136,6 +134,8 @@ var jsonqlConstants = { "WS_OPT_PROP_KEY": "wsOptions", "CONTRACT_PROP_KEY": "contract", "TOKEN_PROP_KEY": "token", + "INIT_CLIENT_PROP_KEY": "nodeClient", + "INIT_CONTRACT_PROP_KEY": "initContract", "CONTENT_TYPE_PROP_KEY": "contentType", "RETURN_AS_PROP_KEY": "returnAs", "NAME_PROP_KEY": "appName", diff --git a/packages/constants/constants.json b/packages/constants/constants.json index eeca1477306c8b04ba9ddf84bf12234d00769da4..4b02861d0b56f99ae2d34e4352b227c7eea07173 100644 --- a/packages/constants/constants.json +++ b/packages/constants/constants.json @@ -86,8 +86,6 @@ ], "NO_ERROR_MSG": "No message", "NO_STATUS_CODE": -1, - "INIT_CLIENT_PROP_KEY": "nodeClient", - "INIT_CONTRACT_PROP_KEY": "initContract", "SUCCESS_STATUS": 200, "UNAUTHORIZED_STATUS": 401, "FORBIDDEN_STATUS": 403, @@ -136,6 +134,8 @@ "WS_OPT_PROP_KEY": "wsOptions", "CONTRACT_PROP_KEY": "contract", "TOKEN_PROP_KEY": "token", + "INIT_CLIENT_PROP_KEY": "nodeClient", + "INIT_CONTRACT_PROP_KEY": "initContract", "CONTENT_TYPE_PROP_KEY": "contentType", "RETURN_AS_PROP_KEY": "returnAs", "NAME_PROP_KEY": "appName", diff --git a/packages/constants/index.js b/packages/constants/index.js index c7de3c37e0877a8785e8f5da2424e01350415e69..6dd6a0787519977760c49117fbcc4b6881beb49c 100644 --- a/packages/constants/index.js +++ b/packages/constants/index.js @@ -117,12 +117,6 @@ export const RETURN_AS_ENUM = [ export const NO_ERROR_MSG = 'No message' export const NO_STATUS_CODE = -1 -// this are property keys used in the configuration options -// and re-use elsewhere -export const INIT_CLIENT_PROP_KEY = 'nodeClient' -export const INIT_CONTRACT_PROP_KEY = 'initContract' - - // status export const SUCCESS_STATUS = 200 export const UNAUTHORIZED_STATUS = 401 @@ -192,6 +186,7 @@ export const WS_OPT_PROP_KEY = 'wsOptions' export const CONTRACT_PROP_KEY = 'contract' export const TOKEN_PROP_KEY = 'token' +export const INIT_CLIENT_PROP_KEY = 'nodeClient' export const INIT_CONTRACT_PROP_KEY = 'initContract' export const CONTENT_TYPE_PROP_KEY = 'contentType' export const RETURN_AS_PROP_KEY = 'returnAs' diff --git a/packages/constants/main.js b/packages/constants/main.js index 83266d1b2e198af779b1792a9cce86686d0bd8b1..85d24f2a6a5e5c1a2c89708734da3868bec4b68b 100644 --- a/packages/constants/main.js +++ b/packages/constants/main.js @@ -86,8 +86,6 @@ module.exports = { ], "NO_ERROR_MSG": "No message", "NO_STATUS_CODE": -1, - "INIT_CLIENT_PROP_KEY": "nodeClient", - "INIT_CONTRACT_PROP_KEY": "initContract", "SUCCESS_STATUS": 200, "UNAUTHORIZED_STATUS": 401, "FORBIDDEN_STATUS": 403, @@ -136,6 +134,8 @@ module.exports = { "WS_OPT_PROP_KEY": "wsOptions", "CONTRACT_PROP_KEY": "contract", "TOKEN_PROP_KEY": "token", + "INIT_CLIENT_PROP_KEY": "nodeClient", + "INIT_CONTRACT_PROP_KEY": "initContract", "CONTENT_TYPE_PROP_KEY": "contentType", "RETURN_AS_PROP_KEY": "returnAs", "NAME_PROP_KEY": "appName", diff --git a/packages/constants/package.json b/packages/constants/package.json index a8be312a6c8a9a9feb8c78bb2655ff85af056750..e4012daf45728a49ffff15bf264ffcd039ab9c16 100755 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-constants", - "version": "2.0.1", + "version": "2.0.2", "description": "All the share constants for jsonql modules", "main": "main.js", "module": "index.js", diff --git a/packages/constants/prop.js b/packages/constants/prop.js index e2a5f36a96da537a4499840084f4c23b55b5b8eb..36b04e27c0131117d9325d544e2010005c4bfbe5 100644 --- a/packages/constants/prop.js +++ b/packages/constants/prop.js @@ -52,6 +52,7 @@ export const WS_OPT_PROP_KEY = 'wsOptions' export const CONTRACT_PROP_KEY = 'contract' export const TOKEN_PROP_KEY = 'token' +export const INIT_CLIENT_PROP_KEY = 'nodeClient' export const INIT_CONTRACT_PROP_KEY = 'initContract' export const CONTENT_TYPE_PROP_KEY = 'contentType' export const RETURN_AS_PROP_KEY = 'returnAs' diff --git a/packages/errors/dist/jsonql-errors.cjs.js b/packages/errors/dist/jsonql-errors.cjs.js index 3955a512748c4499373d6057cc765c214199d682..753b6393eaacebbd5d2146a0797a6e2de5426006 100644 --- a/packages/errors/dist/jsonql-errors.cjs.js +++ b/packages/errors/dist/jsonql-errors.cjs.js @@ -1,2 +1,2 @@ -!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r=r||self).jsonqlErrors={})}(this,(function(r){"use strict";var t=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 406},e.name.get=function(){return"Jsonql406Error"},Object.defineProperties(t,e),t}(Error),e=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"Jsonql500Error"},Object.defineProperties(t,e),t}(Error),o=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 403},e.name.get=function(){return"JsonqlForbiddenError"},Object.defineProperties(t,e),t}(Error),n=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(t,e),t}(Error),a=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(t,e),t}(Error),s=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(t,e),t}(Error),c=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 404},e.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(t,e),t}(Error),i=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(t,e),t}(Error),u=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(t,e),t}(Error),p=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(t,e),t}(Error),l=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(t,e),t}(Error),f="No message",h=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0},statusCode:{configurable:!0}};return e.name.get=function(){return"JsonqlError"},e.statusCode.get=function(){return-1},Object.defineProperties(t,e),t}(Error),m=function(r){function t(e,o){r.call(this,o),this.statusCode=e,this.className=t.name}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlServerError"},Object.defineProperties(t,e),t}(Error),d=Object.freeze({__proto__:null,Jsonql406Error:t,Jsonql500Error:e,JsonqlForbiddenError:o,JsonqlAuthorisationError:n,JsonqlContractAuthError:a,JsonqlResolverAppError:s,JsonqlResolverNotFoundError:c,JsonqlEnumError:i,JsonqlTypeError:u,JsonqlCheckerError:p,JsonqlValidationError:l,JsonqlError:h,JsonqlServerError:m}),g=h,E=function(r,t){return!!Object.keys(r).filter((function(r){return t===r})).length};var y="unknown";function _(r,t){var e=function(r,t){return r.filter((function(r){return t instanceof r})).map((function(r){return r.name}))}(r,t);return e.length?e[0]:y}r.JSONQL_ERRORS_INFO="version: 1.1.10 module: umd",r.Jsonql406Error=t,r.Jsonql500Error=e,r.JsonqlAuthorisationError=n,r.JsonqlCheckerError=p,r.JsonqlContractAuthError=a,r.JsonqlEnumError=i,r.JsonqlError=h,r.JsonqlForbiddenError=o,r.JsonqlResolverAppError=s,r.JsonqlResolverNotFoundError=c,r.JsonqlServerError=m,r.JsonqlTypeError=u,r.JsonqlValidationError=l,r.UNKNOWN_ERROR=y,r.clientErrorsHandler=function(r){if(E(r,"error")){var t=r.error,e=t.className,o=t.name,n=e||o,a=t.message||f,s=t.detail||t;if(n&&d[n])throw new d[e](a,s);throw new g(a,s)}return r},r.finalCatch=function(r){if(Array.isArray(r))throw new l("",r);var d=r.message||f,g=r.detail||r;switch(!0){case r instanceof t:throw new t(d,g);case r instanceof e:throw new e(d,g);case r instanceof o:throw new o(d,g);case r instanceof n:throw new n(d,g);case r instanceof a:throw new a(d,g);case r instanceof s:throw new s(d,g);case r instanceof c:throw new c(d,g);case r instanceof i:throw new i(d,g);case r instanceof u:throw new u(d,g);case r instanceof p:throw new p(d,g);case r instanceof l:throw new l(d,g);case r instanceof m:throw new m(d,g);default:throw new h(d,g)}},r.getErrorByStatus=function(r,t){switch(void 0===t&&(t=!1),r){case 401:return t?"JsonqlContractAuthError":"JsonqlAuthorisationError";case 403:return"JsonqlForbiddenError";case 404:return"JsonqlResolverNotFoundError";case 406:return"Jsonql406Error";case 500:return"Jsonql500Error";default:return"JsonqlError"}},r.getErrorNameByInstance=_,r.getErrorNameByInstanceWithDefault=function(r,t){var e=_(r,t);return e===y?"JsonqlError":e},Object.defineProperty(r,"__esModule",{value:!0})})); +!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r=r||self).jsonqlErrors={})}(this,(function(r){"use strict";var t=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 406},e.name.get=function(){return"Jsonql406Error"},Object.defineProperties(t,e),t}(Error),e=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"Jsonql500Error"},Object.defineProperties(t,e),t}(Error),o=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 403},e.name.get=function(){return"JsonqlForbiddenError"},Object.defineProperties(t,e),t}(Error),n=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(t,e),t}(Error),a=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(t,e),t}(Error),s=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(t,e),t}(Error),c=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 404},e.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(t,e),t}(Error),i=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(t,e),t}(Error),u=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(t,e),t}(Error),p=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(t,e),t}(Error),l=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(t,e),t}(Error),f=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0},statusCode:{configurable:!0}};return e.name.get=function(){return"JsonqlError"},e.statusCode.get=function(){return-1},Object.defineProperties(t,e),t}(Error),h=function(r){function t(e,o){r.call(this,o),this.statusCode=e,this.className=t.name}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"JsonqlServerError"},Object.defineProperties(t,e),t}(Error),m=Object.freeze({__proto__:null,Jsonql406Error:t,Jsonql500Error:e,JsonqlForbiddenError:o,JsonqlAuthorisationError:n,JsonqlContractAuthError:a,JsonqlResolverAppError:s,JsonqlResolverNotFoundError:c,JsonqlEnumError:i,JsonqlTypeError:u,JsonqlCheckerError:p,JsonqlValidationError:l,JsonqlError:f,JsonqlServerError:h}),g=f;function d(r,t){var e=function(r,t){return r.filter((function(r){return t instanceof r})).map((function(r){return r.name}))}(r,t);return e.length?e[0]:"unknown_error"}r.JSONQL_ERRORS_INFO="version: 1.2.0 module: umd",r.Jsonql406Error=t,r.Jsonql500Error=e,r.JsonqlAuthorisationError=n,r.JsonqlCheckerError=p,r.JsonqlContractAuthError=a,r.JsonqlEnumError=i,r.JsonqlError=f,r.JsonqlForbiddenError=o,r.JsonqlResolverAppError=s,r.JsonqlResolverNotFoundError=c,r.JsonqlServerError=h,r.JsonqlTypeError=u,r.JsonqlValidationError=l,r.UNKNOWN_ERROR="unknown_error",r.clientErrorsHandler=function(r){if(c=r,i="error",Object.keys(c).filter((function(r){return i===r})).length){var t=r.error,e=t.className,o=t.name,n=e||o,a=t.message||"No message",s=t.detail||t;if(n&&m[n])throw new m[e](a,s);throw new g(a,s)}var c,i;return r},r.finalCatch=function(r){if(Array.isArray(r))throw new l("",r);var m=r.message||"No message",g=r.detail||r;switch(!0){case r instanceof t:throw new t(m,g);case r instanceof e:throw new e(m,g);case r instanceof o:throw new o(m,g);case r instanceof n:throw new n(m,g);case r instanceof a:throw new a(m,g);case r instanceof s:throw new s(m,g);case r instanceof c:throw new c(m,g);case r instanceof i:throw new i(m,g);case r instanceof u:throw new u(m,g);case r instanceof p:throw new p(m,g);case r instanceof l:throw new l(m,g);case r instanceof h:throw new h(m,g);default:throw new f(m,g)}},r.getErrorByStatus=function(r,t){switch(void 0===t&&(t=!1),r){case 401:return t?"JsonqlContractAuthError":"JsonqlAuthorisationError";case 403:return"JsonqlForbiddenError";case 404:return"JsonqlResolverNotFoundError";case 406:return"Jsonql406Error";case 500:return"Jsonql500Error";default:return"JsonqlError"}},r.getErrorNameByInstance=d,r.getErrorNameByInstanceWithDefault=function(r,t){var e=d(r,t);return"unknown_error"===e?"JsonqlError":e},Object.defineProperty(r,"__esModule",{value:!0})})); //# sourceMappingURL=jsonql-errors.cjs.js.map diff --git a/packages/errors/dist/jsonql-errors.umd.js b/packages/errors/dist/jsonql-errors.umd.js index fe4408382d9cef5124fa2bc4f4d9eb979a4433e7..130132ebb2a227911ad0723717033ef1d2d0f732 100644 --- a/packages/errors/dist/jsonql-errors.umd.js +++ b/packages/errors/dist/jsonql-errors.umd.js @@ -1,2 +1,2 @@ -!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r=r||self).jsonqlErrors={})}(this,(function(r){"use strict";var t=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 406},e.name.get=function(){return"Jsonql406Error"},Object.defineProperties(t,e),t}(Error),e=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"Jsonql500Error"},Object.defineProperties(t,e),t}(Error),o=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 403},e.name.get=function(){return"JsonqlForbiddenError"},Object.defineProperties(t,e),t}(Error),n=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(t,e),t}(Error),a=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(t,e),t}(Error),s=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(t,e),t}(Error),c=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 404},e.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(t,e),t}(Error),i=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(t,e),t}(Error),u=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(t,e),t}(Error),p=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(t,e),t}(Error),l=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(t,e),t}(Error),f="No message",h=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0},statusCode:{configurable:!0}};return e.name.get=function(){return"JsonqlError"},e.statusCode.get=function(){return-1},Object.defineProperties(t,e),t}(Error),m=function(r){function t(e,o){r.call(this,o),this.statusCode=e,this.className=t.name}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlServerError"},Object.defineProperties(t,e),t}(Error),d=Object.freeze({__proto__:null,Jsonql406Error:t,Jsonql500Error:e,JsonqlForbiddenError:o,JsonqlAuthorisationError:n,JsonqlContractAuthError:a,JsonqlResolverAppError:s,JsonqlResolverNotFoundError:c,JsonqlEnumError:i,JsonqlTypeError:u,JsonqlCheckerError:p,JsonqlValidationError:l,JsonqlError:h,JsonqlServerError:m}),g=h,E=function(r,t){return!!Object.keys(r).filter((function(r){return t===r})).length};var y="unknown";function _(r,t){var e=function(r,t){return r.filter((function(r){return t instanceof r})).map((function(r){return r.name}))}(r,t);return e.length?e[0]:y}r.JSONQL_ERRORS_INFO="version: 1.1.10 module: umd",r.Jsonql406Error=t,r.Jsonql500Error=e,r.JsonqlAuthorisationError=n,r.JsonqlCheckerError=p,r.JsonqlContractAuthError=a,r.JsonqlEnumError=i,r.JsonqlError=h,r.JsonqlForbiddenError=o,r.JsonqlResolverAppError=s,r.JsonqlResolverNotFoundError=c,r.JsonqlServerError=m,r.JsonqlTypeError=u,r.JsonqlValidationError=l,r.UNKNOWN_ERROR=y,r.clientErrorsHandler=function(r){if(E(r,"error")){var t=r.error,e=t.className,o=t.name,n=e||o,a=t.message||f,s=t.detail||t;if(n&&d[n])throw new d[e](a,s);throw new g(a,s)}return r},r.finalCatch=function(r){if(Array.isArray(r))throw new l("",r);var d=r.message||f,g=r.detail||r;switch(!0){case r instanceof t:throw new t(d,g);case r instanceof e:throw new e(d,g);case r instanceof o:throw new o(d,g);case r instanceof n:throw new n(d,g);case r instanceof a:throw new a(d,g);case r instanceof s:throw new s(d,g);case r instanceof c:throw new c(d,g);case r instanceof i:throw new i(d,g);case r instanceof u:throw new u(d,g);case r instanceof p:throw new p(d,g);case r instanceof l:throw new l(d,g);case r instanceof m:throw new m(d,g);default:throw new h(d,g)}},r.getErrorByStatus=function(r,t){switch(void 0===t&&(t=!1),r){case 401:return t?"JsonqlContractAuthError":"JsonqlAuthorisationError";case 403:return"JsonqlForbiddenError";case 404:return"JsonqlResolverNotFoundError";case 406:return"Jsonql406Error";case 500:return"Jsonql500Error";default:return"JsonqlError"}},r.getErrorNameByInstance=_,r.getErrorNameByInstanceWithDefault=function(r,t){var e=_(r,t);return e===y?"JsonqlError":e},Object.defineProperty(r,"__esModule",{value:!0})})); +!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r=r||self).jsonqlErrors={})}(this,(function(r){"use strict";var t=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 406},e.name.get=function(){return"Jsonql406Error"},Object.defineProperties(t,e),t}(Error),e=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"Jsonql500Error"},Object.defineProperties(t,e),t}(Error),o=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 403},e.name.get=function(){return"JsonqlForbiddenError"},Object.defineProperties(t,e),t}(Error),n=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(t,e),t}(Error),a=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(t,e),t}(Error),s=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(t,e),t}(Error),c=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 404},e.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(t,e),t}(Error),i=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(t,e),t}(Error),u=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(t,e),t}(Error),p=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(t,e),t}(Error),l=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(t,e),t}(Error),f=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0},statusCode:{configurable:!0}};return e.name.get=function(){return"JsonqlError"},e.statusCode.get=function(){return-1},Object.defineProperties(t,e),t}(Error),h=function(r){function t(e,o){r.call(this,o),this.statusCode=e,this.className=t.name}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"JsonqlServerError"},Object.defineProperties(t,e),t}(Error),m=Object.freeze({__proto__:null,Jsonql406Error:t,Jsonql500Error:e,JsonqlForbiddenError:o,JsonqlAuthorisationError:n,JsonqlContractAuthError:a,JsonqlResolverAppError:s,JsonqlResolverNotFoundError:c,JsonqlEnumError:i,JsonqlTypeError:u,JsonqlCheckerError:p,JsonqlValidationError:l,JsonqlError:f,JsonqlServerError:h}),g=f;function d(r,t){var e=function(r,t){return r.filter((function(r){return t instanceof r})).map((function(r){return r.name}))}(r,t);return e.length?e[0]:"unknown_error"}r.JSONQL_ERRORS_INFO="version: 1.2.0 module: umd",r.Jsonql406Error=t,r.Jsonql500Error=e,r.JsonqlAuthorisationError=n,r.JsonqlCheckerError=p,r.JsonqlContractAuthError=a,r.JsonqlEnumError=i,r.JsonqlError=f,r.JsonqlForbiddenError=o,r.JsonqlResolverAppError=s,r.JsonqlResolverNotFoundError=c,r.JsonqlServerError=h,r.JsonqlTypeError=u,r.JsonqlValidationError=l,r.UNKNOWN_ERROR="unknown_error",r.clientErrorsHandler=function(r){if(c=r,i="error",Object.keys(c).filter((function(r){return i===r})).length){var t=r.error,e=t.className,o=t.name,n=e||o,a=t.message||"No message",s=t.detail||t;if(n&&m[n])throw new m[e](a,s);throw new g(a,s)}var c,i;return r},r.finalCatch=function(r){if(Array.isArray(r))throw new l("",r);var m=r.message||"No message",g=r.detail||r;switch(!0){case r instanceof t:throw new t(m,g);case r instanceof e:throw new e(m,g);case r instanceof o:throw new o(m,g);case r instanceof n:throw new n(m,g);case r instanceof a:throw new a(m,g);case r instanceof s:throw new s(m,g);case r instanceof c:throw new c(m,g);case r instanceof i:throw new i(m,g);case r instanceof u:throw new u(m,g);case r instanceof p:throw new p(m,g);case r instanceof l:throw new l(m,g);case r instanceof h:throw new h(m,g);default:throw new f(m,g)}},r.getErrorByStatus=function(r,t){switch(void 0===t&&(t=!1),r){case 401:return t?"JsonqlContractAuthError":"JsonqlAuthorisationError";case 403:return"JsonqlForbiddenError";case 404:return"JsonqlResolverNotFoundError";case 406:return"Jsonql406Error";case 500:return"Jsonql500Error";default:return"JsonqlError"}},r.getErrorNameByInstance=d,r.getErrorNameByInstanceWithDefault=function(r,t){var e=d(r,t);return"unknown_error"===e?"JsonqlError":e},Object.defineProperty(r,"__esModule",{value:!0})})); //# sourceMappingURL=jsonql-errors.umd.js.map diff --git a/packages/errors/package.json b/packages/errors/package.json index 949bac96afcc419cc93b434087bdfe04b3bca14e..22ee8287c558f1452efbd5be5132b3cf90a063b6 100644 --- a/packages/errors/package.json +++ b/packages/errors/package.json @@ -8,6 +8,7 @@ "scripts": { "prepare": "npm run build", "test": "ava", + "test:debug": "DEBUG=jsonql* ava", "test:server": "ava ./tests/server.test.js", "test:run": "node ./tests/helpers/run.js", "test:fn": "ava ./tests/fn.test.js", @@ -79,6 +80,6 @@ "author": "Joel Chu ", "license": "ISC", "dependencies": { - "jsonql-constants": "^2.0.0" + "jsonql-constants": "^2.0.1" } } diff --git a/packages/errors/src/406-error.js b/packages/errors/src/406-error.js index 35423ef2c1d97132afa24824ca486edaa8c6b5d2..013ace2d95b575c0b35742ec76f156d37e4008bb 100644 --- a/packages/errors/src/406-error.js +++ b/packages/errors/src/406-error.js @@ -1,4 +1,4 @@ - +import { NOT_ACCEPTABLE_STATUS } from './constants' /** * This is a custom error to throw when server throw a 406 * This help us to capture the right error, due to the call happens in sequence @@ -20,11 +20,11 @@ export default class Jsonql406Error extends Error { } static get statusCode() { - return 406; + return NOT_ACCEPTABLE_STATUS } static get name() { - return 'Jsonql406Error'; + return 'Jsonql406Error' } } diff --git a/packages/errors/src/500-error.js b/packages/errors/src/500-error.js index 8be9da56908395b59d41792482395441eed69fc5..9575b7708cacbaf20a39ac1ada817508281ce75a 100644 --- a/packages/errors/src/500-error.js +++ b/packages/errors/src/500-error.js @@ -1,3 +1,5 @@ +import { SERVER_INTERNAL_STATUS } from './constants' + /** * This is a custom error to throw when server throw a 500 * This help us to capture the right error, due to the call happens in sequence @@ -19,7 +21,7 @@ export default class Jsonql500Error extends Error { } static get statusCode() { - return 500 + return SERVER_INTERNAL_STATUS } static get name() { diff --git a/packages/errors/src/authorisation-error.js b/packages/errors/src/authorisation-error.js index 08e6aa01427e2ede73ac33cc085bfd20bbd50e46..2c572b895991716a29e93346cd441ded62bfe5cc 100644 --- a/packages/errors/src/authorisation-error.js +++ b/packages/errors/src/authorisation-error.js @@ -1,4 +1,4 @@ - +import { UNAUTHORIZED_STATUS } from './constants' /** * This is a custom error to throw when pass credential but fail * This help us to capture the right error, due to the call happens in sequence @@ -19,7 +19,7 @@ export default class JsonqlAuthorisationError extends Error { } static get statusCode() { - return 401 + return UNAUTHORIZED_STATUS } static get name() { diff --git a/packages/errors/src/client-errors-handler.js b/packages/errors/src/client-errors-handler.js index 7a69a55791e9e56f33039a3a24adc9a97703a59d..674d37ad79e55445f5d55ec2e84a01df65b94893 100644 --- a/packages/errors/src/client-errors-handler.js +++ b/packages/errors/src/client-errors-handler.js @@ -2,7 +2,7 @@ import * as errors from './index' // import getErrorByStatus from './get-error-by-status' -import { NO_ERROR_MSG } from 'jsonql-constants/base' +import { NO_ERROR_MSG } from './constants' const { JsonqlError } = errors /** diff --git a/packages/errors/src/constants.js b/packages/errors/src/constants.js new file mode 100644 index 0000000000000000000000000000000000000000..a43ed72d903d8dd3a94c6f9405473f0a79030331 --- /dev/null +++ b/packages/errors/src/constants.js @@ -0,0 +1,23 @@ +// group all the constants one place +import { + NOT_ACCEPTABLE_STATUS, + UNAUTHORIZED_STATUS, + FORBIDDEN_STATUS, + NOT_FOUND_STATUS, + SERVER_INTERNAL_STATUS, + NO_STATUS_CODE, + NO_ERROR_MSG +} from 'jsonql-constants/base' + +const UNKNOWN_ERROR = 'unknown_error' + +export { + NOT_ACCEPTABLE_STATUS, + UNAUTHORIZED_STATUS, + FORBIDDEN_STATUS, + NOT_FOUND_STATUS, + SERVER_INTERNAL_STATUS, + NO_STATUS_CODE, + NO_ERROR_MSG, + UNKNOWN_ERROR +} \ No newline at end of file diff --git a/packages/errors/src/contants.js b/packages/errors/src/contants.js deleted file mode 100644 index 79e0a70c8074ffe15a8cc3c26db5b73a0f477222..0000000000000000000000000000000000000000 --- a/packages/errors/src/contants.js +++ /dev/null @@ -1 +0,0 @@ -// group all the constants one place diff --git a/packages/errors/src/contract-auth-error.js b/packages/errors/src/contract-auth-error.js index 95c8acdfacf0de83ad5065d9f6cf5a36a78e0fdc..c1d4248467ee6ac0541c648c83a16abb6041b6d1 100644 --- a/packages/errors/src/contract-auth-error.js +++ b/packages/errors/src/contract-auth-error.js @@ -1,4 +1,4 @@ -import { UNAUTHORIZED_STATUS } from 'jsonql-constants/base' +import { UNAUTHORIZED_STATUS } from './constants' /** * This is a custom error when not supply the credential and try to get contract diff --git a/packages/errors/src/error.js b/packages/errors/src/error.js index d07354541d889ed74802385c4488a244b73d5922..33fd90156232e15b1c86f52886323294c73fe204 100644 --- a/packages/errors/src/error.js +++ b/packages/errors/src/error.js @@ -1,4 +1,4 @@ -import { NO_STATUS_CODE } from 'jsonql-constants/base' +import { NO_STATUS_CODE } from './constants' /** * This is a custom error to throw whenever a error happen inside the jsonql diff --git a/packages/errors/src/forbidden-error.js b/packages/errors/src/forbidden-error.js index fc6f4c8e7ae09a53e428ce2f5abb0c14d2e3600d..2aac703f02632219e65dbb31641eadcab43f0b4e 100644 --- a/packages/errors/src/forbidden-error.js +++ b/packages/errors/src/forbidden-error.js @@ -1,4 +1,4 @@ -import { FORBIDDEN_STATUS } from 'jsonql-constants/base' +import { FORBIDDEN_STATUS } from './constants' /** * this is the 403 Forbidden error * that means this user is not login diff --git a/packages/errors/src/get-error-by-status.js b/packages/errors/src/get-error-by-status.js index a236085b8eee0ed89a77c90d2956e5a31f9435f1..75c9f6223daa51e9c7a0026be34ec22fdd5ea955 100644 --- a/packages/errors/src/get-error-by-status.js +++ b/packages/errors/src/get-error-by-status.js @@ -2,11 +2,11 @@ import { UNAUTHORIZED_STATUS, FORBIDDEN_STATUS, - NOT_FOUND_STATUS -} from 'jsonql-constants' -// not in the constants will add back later -const ERROR_406 = 406 -const ERROR_500 = 500 + NOT_FOUND_STATUS, + NOT_ACCEPTABLE_STATUS, + SERVER_INTERNAL_STATUS +} from './constants' + /** * @param {number} statusCode to check @@ -21,9 +21,9 @@ export default function getErrorByStatus(statusCode, contract = false) { return 'JsonqlForbiddenError' case NOT_FOUND_STATUS: return 'JsonqlResolverNotFoundError' - case ERROR_406: + case NOT_ACCEPTABLE_STATUS: return 'Jsonql406Error' - case ERROR_500: + case SERVER_INTERNAL_STATUS: return 'Jsonql500Error' default: return 'JsonqlError' diff --git a/packages/errors/src/get-error-name-by-instance.js b/packages/errors/src/get-error-name-by-instance.js index d48ab283bd414aab03c1c77bbdbfc581d0762d72..dd5a8cefb1b3444797a1fd6d3b0b8769a0798147 100644 --- a/packages/errors/src/get-error-name-by-instance.js +++ b/packages/errors/src/get-error-name-by-instance.js @@ -1,5 +1,5 @@ // get error name by instance -const UNKNOWN_ERROR = 'unknown' +import { UNKNOWN_ERROR } from './constants' /** * @param {array} errs list of errors to compare from diff --git a/packages/errors/src/resolver-app-error.js b/packages/errors/src/resolver-app-error.js index e11166ff24c99b92e45f7862ab8800ec5808153f..60370ca5b1129fc24be2334cd0e7c160969e1c36 100644 --- a/packages/errors/src/resolver-app-error.js +++ b/packages/errors/src/resolver-app-error.js @@ -1,4 +1,4 @@ - +import { SERVER_INTERNAL_STATUS } from './constants' /** * This is a custom error to throw when the resolver throw error and capture inside the middleware * This help us to capture the right error, due to the call happens in sequence @@ -20,7 +20,7 @@ export default class JsonqlResolverAppError extends Error { } static get statusCode() { - return 500 + return SERVER_INTERNAL_STATUS } static get name() { diff --git a/packages/errors/src/resolver-not-found-error.js b/packages/errors/src/resolver-not-found-error.js index ec5262911059b6f3ca8034c41551dfeb988b2b27..6034fa00a0be7e4afb656414a2d40a85f8261f29 100644 --- a/packages/errors/src/resolver-not-found-error.js +++ b/packages/errors/src/resolver-not-found-error.js @@ -1,4 +1,4 @@ -import { NOT_FOUND_STATUS } from 'jsonql-constants/base' +import { NOT_FOUND_STATUS } from './constants' /** * This is a custom error to throw when could not find the resolver * This help us to capture the right error, due to the call happens in sequence diff --git a/packages/errors/src/server-error.js b/packages/errors/src/server-error.js index 3a4f54e1a6969a0b06a4891360edf8b65dfa3048..ce151f511a65bdae7a40eb28db29f51bde776a18 100644 --- a/packages/errors/src/server-error.js +++ b/packages/errors/src/server-error.js @@ -1,3 +1,5 @@ +import { SERVER_INTERNAL_STATUS } from './constants' + // this is from an example from Koa team to use for internal middleware ctx.throw // but after the test the res.body part is unable to extract the required data // I keep this one here for future reference @@ -11,7 +13,7 @@ export default class JsonqlServerError extends Error { } static get statusCode() { - return 500 + return SERVER_INTERNAL_STATUS } static get name() { diff --git a/packages/errors/tests/main.test.js b/packages/errors/tests/main.test.js index 0d2a3484845cb6a4f954a0f0b6cd0fa1661d4611..d848932f8c0e855c70815f1b74fc19976b681bfd 100644 --- a/packages/errors/tests/main.test.js +++ b/packages/errors/tests/main.test.js @@ -12,13 +12,13 @@ const justThrow = require('./helpers/throw-some-error') const isObjectHasKey = (obj, key) => { const keys = Object.keys(obj); - return !!keys.filter(k => key === k).length; + return !!keys.filter(k => key === k).length } test('Just need to test this isObjectHasKey function', t => { let obj = {error: false}; - t.is(true, isObjectHasKey(obj, 'error')); + t.is(true, isObjectHasKey(obj, 'error')) }) @@ -27,13 +27,14 @@ test('It should throw a resolver application error', t => { const error = t.throws( () => { return resolver(); - } , JsonqlResolverAppError, 'Throw a dummy error'); + } , /* JsonqlResolverAppError */ null, 'Throw a dummy error') + t.is('JsonqlResolverAppError', error.className) - t.is(error.className, 'JsonqlResolverAppError'); - t.true(typeof error.detail === 'object'); - t.is(error.message, 'Dummy'); + t.is(error.className, 'JsonqlResolverAppError') + t.true(typeof error.detail === 'object') + t.is(error.message, 'Dummy') }) test('It should throw a JsonqlResolverNotFoundError with the wrong name', t => { @@ -49,19 +50,21 @@ test('It should throw a JsonqlResolverNotFoundError with the wrong name', t => { } const error = t.throws(() => { fn(); - }, JsonqlResolverNotFoundError, 'It should throw a JsonqlResolverNotFoundError') + }, /* JsonqlResolverNotFoundError*/ null, 'It should throw a JsonqlResolverNotFoundError') // t.is(error.where, 'node') - debug(error) + t.is('JsonqlResolverNotFoundError', error.className) t.is(error.message, name) }) test("Very dummy test to test the test Error instance", async t => { - await t.throwsAsync(async () => { + let error = await t.throwsAsync(async () => { return await justThrow().catch(finalCatch) - }, JsonqlError, 'just throw a JsonqlError') + }, /* JsonqlError */ null, 'just throw a JsonqlError') + + t.is('JsonqlError', error.className) }) diff --git a/packages/errors/tests/server.test.js b/packages/errors/tests/server.test.js index 3923f184a5ab225e9d7545089f1e611a0accfd0c..ff37e82eff06ea21dff01f7b30f2c3853f0b35af 100644 --- a/packages/errors/tests/server.test.js +++ b/packages/errors/tests/server.test.js @@ -2,7 +2,7 @@ const test = require('ava') const server = require('./helpers/server-throw') const superkoa = require('superkoa') - +const { SERVER_INTERNAL_STATUS } = require('jsonql-constants') test.before( t => { t.context.app = server(true) }) @@ -18,8 +18,8 @@ test('It should able to catch the 500 and extract a payload', async t => { } }) - // console.info(res.body); - - t.is(500, res.status) + + // also test the jsonql-constants + t.is(res.status, SERVER_INTERNAL_STATUS) }) diff --git a/packages/jwt/package.json b/packages/jwt/package.json index 5c3eb936184c353d13930dc1a5fb24f7b48a143d..a92aa35c9965f7e94daeca8294ea2ea6ba01d43c 100644 --- a/packages/jwt/package.json +++ b/packages/jwt/package.json @@ -39,8 +39,8 @@ "dependencies": { "colors": "^1.4.0", "fs-extra": "^8.1.0", - "jsonql-constants": "^2.0.0", - "jsonql-errors": "^1.1.10", + "jsonql-constants": "^2.0.1", + "jsonql-errors": "^1.2.0", "jsonql-params-validator": "^1.6.0", "jsonql-utils": "^1.1.3", "jsonwebtoken": "^8.5.1", diff --git a/packages/utils/package.json b/packages/utils/package.json index 131e496522a33efbd5380b16425afba8a039a934..996c146be2433f08cbd10b74c5073c9ea569bc01 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -67,8 +67,8 @@ "verbose": true }, "dependencies": { - "jsonql-constants": "^2.0.0", - "jsonql-errors": "^1.1.10", + "jsonql-constants": "^2.0.1", + "jsonql-errors": "^1.2.0", "lodash-es": "^4.17.15" }, "devDependencies": {