Reputation: 7083
So in main.ts i am trying to call class method processResponse
to get the data back from handler but it always return custObject
undefined its nor even stepping into processResponse
function , what is implemented wrong in below code ?
main.ts
private async custResponse(data: any): Promise < any > {
const custObject = await RequestResponseHandler.processResponse(data);
return custObject;
}
handler.ts
public static async processResponse(data: any): Promise<any> {
let response: any = {};
console.log("Data>>..>>>>", data); // undefined
try {
if (data.Header.StatusCode === "0000") {
response = data.Details;
const tokenId = await this.cacheResponse(response);
response.Header.tokenID = tokenId;
return response;
}
} catch (err) {
return data;
}
}
Upvotes: 1
Views: 405
Reputation: 1546
Since your console.log("Data>>..>>>>", data);
is undefined
that means the issue is somewhere upstream. You are not passing anything in the data argument to this method. Try checking where you are calling custResponse
method and see if the data is actually being passed or not (Its probably not).
As for the undefined return, In your code you are not returning anything if the status code is not OK (In the try block). Try putting some return at the end.
public static async processResponse(data: any): Promise<any> {
//....
//try catch stuff...
//....
return data //or something else
}
Upvotes: 1