joi icon indicating copy to clipboard operation
joi copied to clipboard

abortEarrly = false and formatting the return of multiple errors

Open TomMiller-mas opened this issue 1 year ago • 1 comments

Runtime

node 18, express 4

Runtime version

18, 4 latest on both

Module version

17.7.0"

Used with

express.js

Any other relevant information

It seems to daisy chain the errors into one long string. Is there a way to have them on their own line? /n or
added the string of multiple error messages string.

How can we help?

  try {
    const inputVal = await schemaGetCustProdQuery.validateAsync(inputData, {
      abortEarly: false,
    });
    return inputVal;
  } catch (err) {
    return `${err}`.replace("ValidationError:", "Validation Error:");
  }

TomMiller-mas avatar Dec 20 '23 23:12 TomMiller-mas

Hi,

Right now there is not, although it wouldn't be very hard to add that to the errors options. What you can do though is recreate that from the details:

return `Validation Error: ${err.details.map((detail) => detail.message).join('\n')}`

Is it enough for your needs?

Marsup avatar Feb 21 '24 19:02 Marsup