How to read content directed to stderr using exec api


I am trying to execute a command using docker exec, the output of the command is a error which is written in stderr, but when using exec api, the response is only the content of the stdout, BTW, I am using HTTPUrlConnection for the api request and getErrorStream is always null. So how do I read the content written in stderr? Logically the command execution is success, so the output of exec start will be 200 code. but the execution is a error. I’m not sure if the issue with docker not directing stderr to errorstream or HttpUrlConnection not providing the right errorstream. Please do clarify on this