PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 24, 2022

[FIXED] How to remove backslash from exception message in SpringBoot?

 July 24, 2022     java, json, spring-mvc     No comments   

Issue

I have this exception message:

 public CityDto getCityByName(String name) throws DataNotFoundException {
    CityEntity cityEntity = cityRepository.findByName(name);
    if (cityEntity == null){
        throw new DataNotFoundException("city with name " + '"' + name + '"' + " not found!");
    }else
        return CityMapper.INSTANCE.toCityDto(cityEntity);
}

and this how Postman show me this message:

{
"status": "NOT_FOUND",
"message": "Entity not found",
"errors": [
    "city with name \"Toronto\" not found!"
]

}

As u can see, city name Toronto for some reason have backslash. How to remove it?


Solution

do this throw new DataNotFoundException("city with name '" + name + "' not found!")



Answered By - Artur May
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing