尝试从execute
方法向作为父函数的process
抛出错误,如果execute
方法出错,则返回空对象。如何将错误从子功能返回到调用者功能,以便它可以使用try/catch
将逻辑错误发送回客户端?
main.ts
export class GetSpecialtyQuestionsController extends Controller {
public static async process(@Request() request: ExpressRequest,
response: ExpressResponse): Promise < any > {
try {
const instance = new GetSpecialtyQuestionsController();
const data = await instance.execute(request);
response.status(200);
response.send(data);
} catch (err) {
response.status(200);
response.send(err.message);
}
}
constructor() {
super();
}
private async execute(@Request() request: ExpressRequest): Promise < any > {
// const specialtyMembers = this.getSpecialtyMemberInfoFakeObject();
const specialtyMembers = await new SpecialtyCacheUtility().getSpecialtyMemberInfoCache(
request.body.getSpecialtyQuestionsRequest.header.serviceContext.tokenID);
if (!specialtyMembers) {
return this.errorHandler(request);
}
const body: any = this.buildSingleRequestBody(proxyMember, request.body.getSpecialtyQuestionsRequest);
const requestObject = this.specialtyQuestionRequest(body);
const requestArray: IRequestURL[] = [requestObject];
const data = await makeRequest(requestArray);
return this.mapSpecialtyResponse(data, specialtyMembers);
}
}