You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When you want to provide global error handler for routes which are created "programatically via api" (SpringdocRouteBuilder) we are using SpringdocRouteBuilder.onError()
Now from spring doc:
onError - Filters all exceptions of the given type by applying the given response provider function.
withAttribute - Add an attribute with the given name and value to the last route built with this builder.
So with onError we are defining global behaviour but since withAttribute is applied to LAST created route this looks like unwanted behaviour.
So some-path-B will get override with ERROR_RESPONSE which is imho unwanted behaviour.
My suggestion is to remove call of withAttributes() from onError()
To Reproduce
See example above
Expected behavior
A way how to programatically define GLOBAL error handlers which will not override routes definitions
The text was updated successfully, but these errors were encountered:
ddeath
changed the title
SpringdocRouteBuilder.onError should not accept operationsConsumer
SpringdocRouteBuilder.onError is overriding last route defined
Oct 12, 2023
Describe the bug
When you want to provide global error handler for routes which are created "programatically via api" (SpringdocRouteBuilder) we are using
SpringdocRouteBuilder.onError()
The issue is that it requires us to provide operationsConsumer. First of all I dont understand why we have to provide it, what is reasoning behind that, but second of all it is not use properly.
As we can see here: https://github.com/springdoc/springdoc-openapi/blob/main/springdoc-openapi-starter-webmvc-api/src/main/java/org/springdoc/webmvc/core/fn/SpringdocRouteBuilder.java#L675 operationConsumer is provided to function
withAttribute()
Now from spring doc:
onError - Filters all exceptions of the given type by applying the given response provider function.
withAttribute - Add an attribute with the given name and value to the last route built with this builder.
So with onError we are defining global behaviour but since withAttribute is applied to LAST created route this looks like unwanted behaviour.
Example:
Since we are forced to provide that operationConsumer with onError() method the generated openapi spect will be something like:
So
some-path-B
will get override withERROR_RESPONSE
which is imho unwanted behaviour.My suggestion is to remove call of
withAttributes()
fromonError()
To Reproduce
See example above
Expected behavior
The text was updated successfully, but these errors were encountered: