I find my solution based on simple spring boot app from
Hello World spring boot and modify it to specific exception (anyway it will work for other apps as long as we got app or know framework that provide response) :
curl https://start.spring.io/starter.zip \
-d dependencies=web \
-d name=helloworld \
-d artifactId=helloworld \
-o helloworld.zip
unzip helloworld.zip
Then paste it into class:
import javax.net.ssl.SSLException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class HelloworldApplication {
@RestController
class HelloworldController {
@GetMapping("/") //this will serve get
String hello() throws SSLException {
//this will land in Spring error message text
throw new SSLException("Tested exception javax.net.ssl");
}
}
public static void main(String[] args) {
SpringApplication.run(HelloworldApplication.class, args);
}
}
This will return general json error(same technique of adding exception inside processed request could be used inside servlets or other parts of app that produce response).
Response will look like this
{"timestamp":"2018-08-23T09:22:26.691+0000","status":500,"error":"Internal Server Error","message":"Tested exception javax.net.ssl","path":"/"}