Uh oh!
There was an error while loading. Please reload this page.
[Java] [Spring Client] Add an exception provider interface to allow for exception redefinition - #23878
Conversation
There was a problem hiding this comment.
7 issues found across 70 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
wing328
commented
Jun 3, 2026
thanks for the PR is this change backward compatible? |
…allow for easy exception redefinition
8f01653 to
49ecd01CompareMattias-Sehlstedt
commented
Jun 8, 2026
From an exception-type point of view it is non-breaking. And given that the client re-generates all classes for the library then they should just see a new class that is necessary to add in order for the ApiClient to work as previously. I will investigate how previous changes regarding adding additional generated classes have been conducted to verify that there is no extra conditions that are to be considered. This to make sure that there are no odd clients that have allow-listed file generation or similar that might be impacted differently. |
I have scenarios where I want to have more fine-grained control over the exceptions that an ApiClient can throw. This so that I can handle them more properly by distinguishing them by type and decorating messages. Doing this with the current structure is cumbersome since the same exceptions are redefined in several places, and they are strongly coupled to the enormous
ApiClient.mustache. So I have to customize the base mustache to adjust this behavior.In order to decouple the exception handling and provider better control over it, I suggest that it is extracted into an
ExceptionProvider. This retains the current behavior of the exceptions thrown currently, but it also provides an extension point where these can be easily configured as a separate concept. Either with theExceptionProvider.mustache, or by injecting an extended interface into theApiClient.This approach is currently tailored towards Spring's
RestClientandWebClientonly.RestTemplateis intentionally omitted, since it is deprecated.PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)cc @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)
Summary by cubic
Adds an
ExceptionProviderinterface for SpringRestClientandWebClientclients so users can redefine thrown exceptions without editingApiClient.mustache. Default behavior is unchanged and exception handling is now decoupled and injectable.New Features
ExceptionProvider.javafromExceptionProvider.mustacheforwebclientandrestclient.exceptionProviderfield with getter/setter in generatedApiClient; defaults toExceptionProvider.DEFAULT.JavaClientCodegento include the supporting file for these libraries.Migration
ExceptionProviderand callapiClient.setExceptionProvider(...).RestClientandWebClientonly;RestTemplateis not included.Written for commit 49ecd01. Summary will update on new commits.