alibaba / nacos

an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
https://nacos.io
Apache License 2.0
30.07k stars 12.81k forks source link

Response wrong status code for some situation for openAPI #11842

Closed KomachiSion closed 5 months ago

KomachiSion commented 6 months ago

Describe the bug Some situation for openAPI will return wrong status code, such as:

Register one persistent instance for A service first, and then try to register one ephemeral instance to A service. For expected get an 400 error because a persistent service can't register ephemeral instance, the error message is right. But the status code is 500.

For research, The reason is the check logic is throw the NacosRuntimeException with 400 errorCode, But the ResponseExceptionHandler in nacos-naming module did not handle NacosRuntimeException type but as normal Exception to handle, which will cause the status code is 500.

Expected behavior NacosRuntimeException can be handle right and the response status code can same with NacosRuntimeException.

Actually behavior NacosRuntimeException will all change to 500 code.

Additional context BTW, expect ResponseExceptionHandler in nacos-naming , other ExceptionHandler such as GlobalExceptionHandler in nacos-config, ConsoleExceptionHandler in nacos-console, PrometheusApiExceptionHandler in nacos-prometheus also should handle NacosRuntimeException.

shalk commented 6 months ago

i will resolve it