fix(core): update
This commit is contained in:
		@@ -1,4 +1,5 @@
 | 
			
		||||
import * as plugins from './typedrequest.plugins';
 | 
			
		||||
import { TypedResponseError } from './typedrequest.classes.typedresponseerror';
 | 
			
		||||
 | 
			
		||||
type THandlerFunction<T extends plugins.typedRequestInterfaces.ITypedRequest> = (
 | 
			
		||||
  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'
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
    const response = await this.handlerFunction(typedRequestArg.request);
 | 
			
		||||
    typedRequestArg.response = response;
 | 
			
		||||
    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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    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;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user