How to return error from child fucntion to caller function using async?
up vote
0
down vote
favorite
trying to throw error from execute
method to process
that is parent function , if there is error in execute
method it returns empty object. How to return error from child function to caller function so it can send logical error back to client using 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);
}
}
javascript angular typescript error-handling try-catch
add a comment |
up vote
0
down vote
favorite
trying to throw error from execute
method to process
that is parent function , if there is error in execute
method it returns empty object. How to return error from child function to caller function so it can send logical error back to client using 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);
}
}
javascript angular typescript error-handling try-catch
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
trying to throw error from execute
method to process
that is parent function , if there is error in execute
method it returns empty object. How to return error from child function to caller function so it can send logical error back to client using 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);
}
}
javascript angular typescript error-handling try-catch
trying to throw error from execute
method to process
that is parent function , if there is error in execute
method it returns empty object. How to return error from child function to caller function so it can send logical error back to client using 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);
}
}
javascript angular typescript error-handling try-catch
javascript angular typescript error-handling try-catch
asked Nov 5 at 3:40
hussain
1,29952150
1,29952150
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53148014%2fhow-to-return-error-from-child-fucntion-to-caller-function-using-async%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password