fix(core): update
This commit is contained in:
parent
f98c2cc5e7
commit
2879fb8cee
@ -1,4 +1,5 @@
|
|||||||
import * as plugins from './typedrequest.plugins';
|
import * as plugins from './typedrequest.plugins';
|
||||||
|
import { TypedResponseError } from './typedrequest.classes.typedresponseerror';
|
||||||
|
|
||||||
type THandlerFunction<T extends plugins.typedRequestInterfaces.ITypedRequest> = (
|
type THandlerFunction<T extends plugins.typedRequestInterfaces.ITypedRequest> = (
|
||||||
requestArg: T['request']
|
requestArg: T['request']
|
||||||
@ -26,8 +27,27 @@ export class TypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest
|
|||||||
'this handler has been given a wrong method to answer to. Please use a TypedRouter to filter requests'
|
'this handler has been given a wrong method to answer to. Please use a TypedRouter to filter requests'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const response = await this.handlerFunction(typedRequestArg.request);
|
let typedResponseError: TypedResponseError;
|
||||||
|
const response = await this.handlerFunction(typedRequestArg.request).catch(e => {
|
||||||
|
if (e instanceof TypedResponseError) {
|
||||||
|
typedResponseError = e;
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (typedResponseError) {
|
||||||
|
typedRequestArg.error = {
|
||||||
|
text: typedResponseError.errorText,
|
||||||
|
data: typedResponseError.errorData
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response) {
|
||||||
typedRequestArg.response = response;
|
typedRequestArg.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return typedRequestArg;
|
return typedRequestArg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
ts/typedrequest.classes.typedresponseerror.ts
Normal file
10
ts/typedrequest.classes.typedresponseerror.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import * as plugins from './typedrequest.plugins';
|
||||||
|
|
||||||
|
export class TypedResponseError {
|
||||||
|
public errorText: string;
|
||||||
|
public errorData: any;
|
||||||
|
constructor(errorTextArg: string, errorDataArg: any) {
|
||||||
|
this.errorText = errorTextArg;
|
||||||
|
this.errorData = errorDataArg;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user