spring-projects / spring-projects/spring-data-rest

SDR doesn't display custom global errors [DATAREST-700]

Open
#1,071 1 comment 1 reaction 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Willie Wheeler opened DATAREST-700 and commented

I have a custom validator that I've registered through RepositoryRestConfigurerAdapter.configureValidatingRepositoryEventListener(). Validation is working.

However only validation errors generated by errors.rejectValue(...) show up in the SDR JSON response. So e.g. this works as expected:

errors.rejectValue(
    "company",
    "customer.active.companyNotNull",
    "Active customer must have a defined company.");

I.e., it generates

{
    "errors": [{
        "entity":"Customer",
        "message":"Active customer must have a defined company.",
        "invalidValue":"null",
        "property":"company"
    }]
}

If on the other hand I do errors.reject(...) to generate a global error, it doesn't appear in the response. E.g.,

errors.reject(
    "customer.active.companyNotNull",
    "Active customers must have a defined company.");

generates

{ errors: [0] }

even though validation has actually failed. I do get the HTTP 400 and I do see my validation failure log messages on the console.

Leaving aside the question of whether I ought to be using a field error or a global error here, it seems that global errors should still show up in the output.


Affects: 2.4 GA (Gosling)

2 votes, 3 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.