-2

SO I think I am having a brain fart, I am trying to get the values for these three different error responses.

message validation

{
  "errors": [
    {
      "message": "Validation failed for the field [confirmAppointment].",
      "extensions": {
        "validation": {
          "input.birth_date": [
            "The input.birth date must be a date before today."
          ]
        },
        "category": "validation"
      },
      "locations": [
        {
          "line": 1,
          "column": 11
        }
      ],
      "path": [
        "confirmAppointment"
      ]
    }
  ],
  "data": {
    "confirmAppointment": null
  }
}

I get this response during an axios catch, id like to display this msg back to the user during validation, however, I think I am having a brain fart.

So far I tried this:

let result = err.response.data.errors.extensions.map(a => a);

This gives me the array of object

enter image description here

any Ideas?

chewie
  • 529
  • 4
  • 17
  • According to the screenshot (that should not be there...) it doesn't hurt to read [How to return the response from an asynchronous call](https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call) – Andreas Sep 09 '21 at 11:03
  • @Andreas the problem is not that I am NOT getting the response with errors but trying to loop through the response and getting what its needed. – chewie Sep 09 '21 at 11:11

1 Answers1

0

Your code:

let result = err.response.data.errors.extensions.map(a => a);

extensions is an object. errors is an array, so you need to:

let result = err.response.errors.map(a => a);
SirOneOfMany
  • 929
  • 5
  • 15