0

I have responses from both promises but when i combineResponse it only resolve one response from ptmResponse promise , What is implemented wrong in below code using spread ? response is coming as object that i want to push it to array.

main.ts

try {
  const __data: IResponse = await makeRequest(this._request);
  const specResponse = await this.specResponse(__data.Details[0]);
  const ptmResponse = await this.ptmAccountBalanceResponse(__data.Details[1]);
  const combineResponse = {
    ...specResponse,
    ...ptmResponse
  };
  return Promise.resolve(combineResponse);
} catch (err) {
  return Promise.reject(err);
}
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
hussain
  • 6,587
  • 18
  • 79
  • 152

2 Answers2

2

You might be overthinking this one. I'm assuming you want an array containing both objects. If so, then it's just:

const combineResponse = [ specResponse, ptmResponse ]

No spread needed.

Joseph
  • 117,725
  • 30
  • 181
  • 234
0

I would also fire those promises in parallel with Promise.all and store both responses in combineResponse as an array:

const combineResponse = await Promise.all([this.specResponse(__data.Details[0]), this.ptmAccountBalanceResponse(__data.Details[1])]);
Leonid Pyrlia
  • 1,594
  • 2
  • 11
  • 14