0

i'm trying to change the default message that appears whenever a user tries to send a request to the backend and his token has expired. The default message is:

translation-not-found[Unauthorized: Full authentication is required to access this resource]

As result of the InsufficientAuthenticationException.

I want to change it to something understandable for the user. As maybe:

Your session has expired, please log in again!

What i've tried:

  • I search for InsufficientAuthenticationException in the backend and i found no reference.
  • I debug the post request with an expired token, but it never enters the breakpoint.

Here's the post request code:

@PostMapping("/images")
@Timed
public ResponseEntity<Image> createImage(@Valid @RequestBody Image image) throws URISyntaxException {
    log.debug("REST request to save Imagen : {}", imagen);
    if (imagen.getId() != null) {
        throw new BadRequestAlertException("A new image cannot already have an ID", ENTITY_NAME, "idexists");
    }
    Image result = fileServerService.saveImage(image);
    result = imagenRepository.save(result);
    return ResponseEntity.created(new URI("/api/images/" + result.getId()))
        .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString()))
        .body(result);
}

But i don't think it has to do with this part of the code, as it never enters the brakpoint.

My questions are:

  • Where is this error message located?
  • Can i change it in a translation file in the frontend?

Thanks for your time! Have a good day.

Rohr Facu
  • 607
  • 1
  • 12
  • 29

1 Answers1

1

I've managed to solve it by adding the translation in the global.json file, i just added this line at the same level that "global": {} :

"Unauthorized: Full authentication is required to access this resource": "The translation that i want",
"global": {
    ...global stuff..
}
Rohr Facu
  • 607
  • 1
  • 12
  • 29