jboss EAP + spring rest controller
My problem is with error response, even though i am throwing exception with error msg client receives html error page from jboss. which do not have my error msg.. so my code fails to parse the error and in result i have to display generic error msg.
Following is my rest controller implementation
@RequestMapping(value = "/save", method = RequestMethod.POST, produces = "application/json")
public ResponseEntity<PModel> saveProgram(Authentication authentication, @RequestBody PModel p){
m = pService.saveP(p, authentication.getName());
return new ResponseEntity<PModel>(m, HttpStatus.OK);
}
my pService.save throws an error as following
Save(){
…
throw new RuntimeException("ID not found: "+model.id);
}
my angular post request as following
getP
(p: P):Observable<P>{
return this.http.post('api/program/types', p, this.prepareHeaderInfo()) // ...using post request
.map((res:Response) => res.json() as P) // ...and calling .json() on the response to return data
.catch((error:any) => Observable.throw(error.json().error || 'Server error')); //...errors if
}
response i receives as error as html as following without my error
<html><head><title>JBoss Web/-redhat-1 - JBWEB000064: Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>JBWEB000065: HTTP Status 400 - </h1><HR size="1" noshade="noshade"><p><b>JBWE: type</b> JBWE: Status report</p><p><b>JBWE: message</b> <u></u></p><p><b>JBWE: description</b> <u>JBWE: The request sent by the client was syntactically incorrect.</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.5.7.Final-redhat-1</h3></body></html>