Skip to content

Add configurable default value for ThrowOnError #961

Closed
@MrLepage

Description

@MrLepage

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature 🚀New feature or requestprioritized 🚚This issue has been prioritized and will be worked on soon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions