Skip to content

Machine readable validation errors #99

@jankuca

Description

@jankuca

Currently, there is the exception.code info available on certain validation errors but not nearly all errors can be processed without parsing the human-readable error message.

I would like to process validation errors and for instance present various error-specific responses from my API and the best I can do now without parsing the message is to separate 404 and 400 errors.

Proposal: I'm proposing adding new metadata to the exceptions which would precisely describe the validation issue. Results in a format similar to the following would be nice:

exception.code = 'BAD_PARAMS'
exception.params: Array<{
  code: 'missing' | 'invalid' | 'duplicate',
  location: 'path' | 'query' | 'header',
  key: string,
  value: unknown,
}>

Example: For a query parameter not matching a specified string pattern, the result.error.params info would contain an item such as { code: 'invalid', location: 'query', key: 'email', value: 'the invalid value' }.

What are your thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions