-
-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configurable default value for ThrowOnError #961
Comments
Agree that this should be a generator option. Meanwhile my work around is to add this post-generator step: find ./src/clients -type f | xargs perl -pi -e 's/ThrowOnError extends boolean = false/ThrowOnError extends boolean = true/' |
This was the first blocker I hit. When reviewing the docs I just assumed there was a way to configure this globally since the hard part appears to have been done (i.e. altering typescript types and allowing the config value to be specified at the individual method level). It's even more confusing because you can actually configure it with @snarky-puppy thanks for the snippet. That looks like it would address the inferred return types only so those finding this should be aware that Otherwise love with this library is going! |
Liked the solution presented by the OP. This should be included in the CLI too. In the meantime, using the solution proposed by @snarky-puppy above, but in a JS script: function replaceThrowOnError() {
const clientFile = './src/client/services.gen.ts';
fs.readFile(clientFile, 'utf8', (err, data) => {
if (err) {
console.error('Error:', err);
return;
}
const result = data.replace(
/ThrowOnError extends boolean = false/g,
'ThrowOnError extends boolean = true',
);
fs.writeFile(clientFile, result, 'utf8', (err) => {
if (err) {
console.error('Error:', err);
return;
}
console.info('ThrowOnError default replaced successfully!');
});
});
} |
Would be really glad for this kind of feature, in general passing a client-per-call is a little cumbersome but together with this config it adds a lot of overhead to each call |
we are using |
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:
Example configuration:
With this configuration, all generated API request functions would default to throwing errors unless explicitly overridden.
Benefits:
The text was updated successfully, but these errors were encountered: