wispy-oliveW
Refine10mo ago
4 replies
wispy-olive

Error returns the message as an array instead of a string

this is my api response
{"statusCode":400,"message":"This name is already taken","error":"Bad Request","errors":{"name":["This name is already taken"]}}


but when i call the following function

  async function onSubmit(values) {
    try {
      await mutate(
        { values },
        {
          onError: (error) => {
              //TODO: Handle error with notifcationprovider
            console.log(error)
          },
          onSuccess: (data) => {
            setOpen(false)
            router.push(
              `/groups/${data?.data?.id}`,
            )
          },
        },
      )
    } catch (error) {
      //TODO: Handle error with notifcationprovider
      console.error(error)
    }
  }


the onError returns

{
  "statusCode": 400,
  "message": "Bad Request",
  "errors": {
    "": [
      "T",
      "h",
      "i",
      "s",
      " ",
      "n",
      "a",
      "m",
      "e",
      " ",
      "i",
      "s",
      " ",
      "a",
      "l",
      "r",
      "e",
      "a",
      "d",
      "y",
      " ",
      "t",
      "a",
      "k",
      "e",
      "n"
    ]
  }
}


i'm using nextjscrud dataprovider and useCreate mutation
Was this page helpful?