Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

springboot API throws 500 error but no error is logged

I have a springboot api. Call to one of the endpoint from swagger throws 500 error but nothing is getting logged. When I tried debugging, I can see that the responseEntity is populated just before returning from the controller. Hence I feel the code worked fine. Even then I see 500 in swagger. Lack of logs is making is difficult to debug. Did anyone face similar issue? How did you resolve it?

endpoint looks like this: I have added the log statements for reference

@RequestMapping(value = "/details/id/{id}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public @ResponseBody
    ResponseEntity<Details> getDetailsById(@PathVariable(name="id")  @ApiParam(value ="id", example = "1234", required = true) String id) {
        inputValidation.validateInputAndThrowErrorIfNecessary(id);
        if(isBlank(id)) throw new IllegalArgumentException();

        Details details = detailsService.getDetailsById(id);

        if(details == null){
            logger.debug("Not found response..................");
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
        logger.debug("Just before posting the response for  : {}", id);
        ResponseEntity<Details> responseEntity = new ResponseEntity<>(details, HttpStatus.OK);
        logger.debug("JSON--->\n"+responseEntity.toString()); // i see <200 OK OK,class Details { blah blah } at this point in logs

        return responseEntity;
    }

When I run the curl, response is as below :

curl -v GET "http://host:port/api/details/id/111" -H "accept: application/json;charset=UTF-8"
* Rebuilt URL to: GET/
* Could not resolve host: GET
* Closing connection 0
curl: (6) Could not resolve host: GET
*   Trying host...
* TCP_NODELAY set
* Connected to host (host) port port (#1)
> GET /api/details/id/111 HTTP/1.1
> Host: host:port
> User-Agent: curl/7.55.1
> accept: application/json;charset=UTF-8
>
< HTTP/1.1 500
< Content-Type: text/html;charset=utf-8
< Content-Language: en
< Content-Length: 455
< Date: Wed, 27 May 2020 00:49:11 GMT
< Connection: close
<
<!doctype html><html lang="en"><head><title>HTTP Status 500 ÔÇô Internal Server Error</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 500 ÔÇô Internal Server Error</h1></body></html>* Closing connection 1

like image 442
np10 Avatar asked May 02 '26 20:05

np10


1 Answers

I had this problem while declaring a @PathVariable with no correspondence on the @RequestMapping url (thanks to a typo...)

Its not exactly your case (your @PathVariable exists on the url), but may be a the similar thing (two configurations that should match to work are not matching...)

like image 53
Frederico Silva Guimarães Avatar answered May 05 '26 10:05

Frederico Silva Guimarães



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!