react-recurly icon indicating copy to clipboard operation
react-recurly copied to clipboard

Error return value does not match RecurlyError type signature

Open froesecom opened this issue 4 years ago • 1 comments

Issue:

When validating user input errors, the type of "error" returned by recurly.token in this example, recurly.token(formRef.current, (error, token) => {} does not match the RecurlyError type defined by Recurly.js .

recurly.token errors have this structure:

{
  "name": "validation",
  "code": "validation",
  "message": "There was an error validating your request.",
  "fields": [
    "number",
    "month",
    "year"
  ],
  "details": [
    {
      "field": "number",
      "messages": [
        "is invalid"
      ]
    },
    {
      "field": "month",
      "messages": [
        "is invalid"
      ]
    },
    {
      "field": "year",
      "messages": [
        "is invalid"
      ]
    }
  ]
}

RecurlyError is defined by Recurly.js as:

export interface RecurlyError extends Error {
  code: string;
  message: string;
  classification: string;
  help?: string;
}

When using TypeScript, this causes compilation errors if you try to handle the actual response from Recurly.js.

To Reproduce

The bug can be reproduced by inputting an invalid credit card expiry date in the React Recurly demo page and checking the console output.

Expected behavior

The returned error matches the type defined by Recurly.js

Your Environment

  • Using ReactReculry 1.2.3

froesecom avatar Feb 09 '21 00:02 froesecom

Any updates on this? Struggling with it when trying to do proper error handling on our code.

Thank you.

javimbk avatar Oct 12 '21 10:10 javimbk