fix(core): update
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import * as plugins from './typedrequest.plugins';
|
||||
|
||||
type THandlerFunction<T extends plugins.typedRequestInterfaces.ITypedRequest> = (requestArg: T['request']) => Promise<T['response']>;
|
||||
type THandlerFunction<T extends plugins.typedRequestInterfaces.ITypedRequest> = (
|
||||
requestArg: T['request']
|
||||
) => Promise<T['response']>;
|
||||
|
||||
/**
|
||||
* typed handler for dealing with typed requests
|
||||
@ -20,7 +22,9 @@ export class TypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
*/
|
||||
public async addResponse(typedRequestArg: T) {
|
||||
if (typedRequestArg.method !== this.method) {
|
||||
throw new Error('this handler has been given a wrong method to answer to. Please use a TypedRouter to filter requests');
|
||||
throw new Error(
|
||||
'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);
|
||||
typedRequestArg.response = response;
|
||||
|
@ -25,7 +25,11 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
|
||||
if (responseBody.error) {
|
||||
console.log(responseBody.error.text);
|
||||
console.log(responseBody.error.data);
|
||||
return null;
|
||||
}
|
||||
return response.body.response;
|
||||
if (responseBody.retry) {
|
||||
console.log('server requested retry');
|
||||
};
|
||||
return responseBody.response;
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,9 @@ export class TypedRouter {
|
||||
* adds the handler to the routing map
|
||||
* @param handlerArg
|
||||
*/
|
||||
public addTypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest>(handlerArg: TypedHandler<T>) {
|
||||
public addTypedHandler<T extends plugins.typedRequestInterfaces.ITypedRequest>(
|
||||
handlerArg: TypedHandler<T>
|
||||
) {
|
||||
this.handlerMap.add(handlerArg);
|
||||
}
|
||||
|
||||
@ -27,7 +29,7 @@ export class TypedRouter {
|
||||
|
||||
if (!typedHandler) {
|
||||
const availableMethods: string[] = [];
|
||||
await this.handlerMap.forEach(async (handler) => {
|
||||
await this.handlerMap.forEach(async handler => {
|
||||
availableMethods.push(handler.method);
|
||||
});
|
||||
console.log(`Cannot find method for ${typedHandler}`);
|
||||
|
@ -5,7 +5,8 @@ export { typedRequestInterfaces };
|
||||
|
||||
// pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smartjson from '@pushrocks/smartjson';
|
||||
|
||||
export { lik, smartrequest, smartjson };
|
||||
export { lik, smartdelay, smartrequest, smartjson };
|
||||
|
Reference in New Issue
Block a user