data icon indicating copy to clipboard operation
data copied to clipboard

Error if payload===null

Open Makan-seequent opened this issue 2 years ago • 3 comments

Sorry not following the issue reporting instruction but this one is a simple error happening here If the backend response payload=null (I know it shouldn't) and because Javascript consider the "null" as an object it throws error when trying resolve "payload.errors" Indeed it passes through the guard that I think it's provided to prevent this kind of errors.

    if (this.isSuccess(status, headers, payload)) {
      return payload;
    } else if (this.isInvalid(status, headers, payload)) {
      return new InvalidError(typeof payload === 'object' && 'errors' in payload ? payload.errors : undefined);
    }

Makan-seequent avatar Mar 08 '22 02:03 Makan-seequent

@Makan-seequent Do you have a PR you would like to contribute? Or anyway I can help?

snewcomer avatar Apr 12 '22 03:04 snewcomer

@snewcomer Not really I don't have PR as I'm not sure where is the right place to consolidate this guard. But I can imagine something like bellow code which payload && added may works.

return new InvalidError(payload && typeof payload === 'object' && 'errors' in payload ? payload.errors : undefined);

Thank you for taking care of this.

Makan-seequent avatar Apr 12 '22 04:04 Makan-seequent

Hey, I will start working on this you can assign this to me

mani-rsg avatar Oct 29 '22 06:10 mani-rsg