1

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; } } 
15
  • How did you arrive at this assumption, i.e. how are you testing/verifying your code? Commented Aug 28, 2018 at 16:33
  • 1
    Note in your try block you don't return anything if your if statement fails Commented Aug 28, 2018 at 16:34
  • i have debug mode on its assinging undefined to custObject Commented Aug 28, 2018 at 16:34
  • 5
    My guess is the typo: data.Header.StatusCode === "2200" should be data.Header.StatusCode === "200". This is causing your response not to return, thus causing undefined. Commented Aug 28, 2018 at 16:34
  • 2
    Is data.Header.StatusCode definitely a string, or could something be converting it to a number, causing the === comparison to evaluate to false? Commented Aug 28, 2018 at 16:36

1 Answer 1

1

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 } 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man, solved a similar issue returning a new Promise inside a try/catch block!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.