@artus/core
Advanced tools
Comparing version 1.0.0-beta.31 to 1.0.0-beta.32
@@ -51,2 +51,3 @@ "use strict"; | ||
'exception', | ||
'exception-filter', | ||
'plugin-config', | ||
@@ -53,0 +54,0 @@ 'plugin-meta', |
@@ -12,3 +12,3 @@ "use strict"; | ||
}, target); | ||
Reflect.defineMetadata(constant_1.HOOK_FILE_LOADER, { loader: 'exception_filter' }, target); | ||
Reflect.defineMetadata(constant_1.HOOK_FILE_LOADER, { loader: 'exception-filter' }, target); | ||
(0, injection_1.Injectable)()(target); | ||
@@ -15,0 +15,0 @@ }; |
@@ -1,3 +0,4 @@ | ||
import { Container } from '@artus/injection'; | ||
import { Constructable, Container } from '@artus/injection'; | ||
import { ExceptionFilterType } from './types'; | ||
export declare const matchExceptionFilterClazz: (err: Error, container: Container) => Constructable<ExceptionFilterType> | null; | ||
export declare const matchExceptionFilter: (err: Error, container: Container) => ExceptionFilterType | null; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.matchExceptionFilter = void 0; | ||
exports.matchExceptionFilter = exports.matchExceptionFilterClazz = void 0; | ||
const constant_1 = require("./constant"); | ||
const impl_1 = require("./impl"); | ||
const matchExceptionFilter = (err, container) => { | ||
const matchExceptionFilterClazz = (err, container) => { | ||
const filterMap = container.get(constant_1.EXCEPTION_FILTER_MAP_INJECT_ID, { | ||
@@ -13,26 +13,23 @@ noThrow: true, | ||
} | ||
let targetFilterClazz; | ||
// handle ArtusStdError with code simply | ||
let targetFilterClazz = null; | ||
if (err instanceof impl_1.ArtusStdError) { | ||
// handle ArtusStdError with code simply | ||
targetFilterClazz = filterMap.get(err.code); | ||
} | ||
if (!targetFilterClazz) { | ||
// handler other Exception by Clazz | ||
for (const errorClazz of filterMap.keys()) { | ||
if (typeof errorClazz === 'string' || typeof errorClazz === 'symbol') { | ||
continue; | ||
} | ||
if (err instanceof errorClazz) { | ||
targetFilterClazz = filterMap.get(errorClazz); | ||
break; | ||
} | ||
} | ||
else if (filterMap.has(err['constructor'])) { | ||
// handle CustomErrorClazz | ||
targetFilterClazz = filterMap.get(err['constructor']); | ||
} | ||
if (!targetFilterClazz && filterMap.has(constant_1.EXCEPTION_FILTER_DEFAULT_SYMBOL)) { | ||
else if (filterMap.has(constant_1.EXCEPTION_FILTER_DEFAULT_SYMBOL)) { | ||
// handle default ExceptionFilter | ||
targetFilterClazz = filterMap.get(constant_1.EXCEPTION_FILTER_DEFAULT_SYMBOL); | ||
} | ||
return targetFilterClazz; | ||
}; | ||
exports.matchExceptionFilterClazz = matchExceptionFilterClazz; | ||
const matchExceptionFilter = (err, container) => { | ||
const filterClazz = (0, exports.matchExceptionFilterClazz)(err, container); | ||
// return the instance of exception filter | ||
return targetFilterClazz ? container.get(targetFilterClazz) : null; | ||
return filterClazz ? container.get(filterClazz) : null; | ||
}; | ||
exports.matchExceptionFilter = matchExceptionFilter; |
@@ -52,4 +52,4 @@ "use strict"; | ||
ExceptionFilterLoader = tslib_1.__decorate([ | ||
(0, decorator_1.DefineLoader)('exception_filter') | ||
(0, decorator_1.DefineLoader)('exception-filter') | ||
], ExceptionFilterLoader); | ||
exports.default = ExceptionFilterLoader; |
{ | ||
"name": "@artus/core", | ||
"version": "1.0.0-beta.31", | ||
"version": "1.0.0-beta.32", | ||
"description": "Core package of Artus", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
107709
2581