Closed
Description
Currently, services generated code sets the default value of ThrowOnError to false for all API request functions. This default behavior requires developers to explicitly set ThrowOnError to true for each individual API call when they want exceptions to be thrown on errors.
I propose adding a configuration option that allows setting the default value of ThrowOnError globally. This enhancement would significantly improve developer experience and code consistency for projects that prefer a "throw-by-default" error handling strategy.
Proposed changes:
- Add a new configuration option in the configuration file to set the default ThrowOnError value.
- Update the code generation logic to use this configured default when generating API request functions.
Example configuration:
export default defineConfig({
// ... other configuration options
services: {
throwOnError: true, // New option
},
});
With this configuration, all generated API request functions would default to throwing errors unless explicitly overridden.
Benefits:
- Improved code consistency across the application.
- Reduced boilerplate by eliminating the need to specify or throwOnError: true for each API call.
- Better alignment with different error handling strategies preferred by different development teams.
- Maintains flexibility by still allowing per-request override of the behavior.