Wouter
Wouter

Reputation: 1778

JHipster - Improve error messages on frontend

When I want to delete an entity that is linked to other entities in JHipster, the modal shows the expected error:

error.internalServerError

However, it would be nice if JHipster could show a nice error message that explains there is other data linked and you should delete that first.

Does JHipster provide tools for returning meaningful errors like this?

Upvotes: 0

Views: 865

Answers (2)

duderoot
duderoot

Reputation: 987

in the class ExceptionTranslator are some common errors handled. When you are deleting a resource which is referred over a foreign key in some children, then a org.springframework.dao.DataIntegrityViolationException is thrown. This exception is handled in the method processRuntimeException.

In order to create other message you can use create a

@ExceptionHandler(DataIntegrityViolationException.class)
public ResponseEntity<ErrorVM> processDataIntegrityViolationException(DataIntegrityViolationException ex){
}

The question is: what will be the message that you want to add? IMHO I think that you should catch the exception at the place where the call was done and then you can create a proper message that can be sent to the user.

Upvotes: 0

David Steiman
David Steiman

Reputation: 3145

there are two ways to go to achieve this, which depends on the error itself.

If the error is thrown by your self, use the CustomParameterizedException class. This gets automatically passed to the angular error resolver, so you will get a nice message, you defined.

If the error occurs somewhere inside spring, and you want to get a clearer message, I personally prefer to change the ExceptionTranslator class, and change the plain "internalServerError" to e.getMessage().

You may limit this to dev profile for security reasons.

Upvotes: 1

Related Questions