RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.61k stars 1.22k forks source link

Better defaults for `ExceptionDescription`? #4901

Open sheam opened 1 month ago

sheam commented 1 month ago

By default the process function the typescript client uses A server side error occurred for all expected errors. In the case of 400, and 403 this doesn't really make sense. So I would like to change the message used to more closely resemble the error code.

From looking at the Client.ProcessResponse.HandleStatusCode template, it looks like it uses an response.ExceptionDescription property. This is nice for making changes to individual endpoints. But it would be nice if there was a way to say if it is a 403 default the description to "Forbidden" or something more related to the httpCode. Otherwise, I am copy and pasting the same strings everywhere.

Is there a way I can do this in my configuration? Or would I need to override the whole template: https://github.com/RicoSuter/NSwag/blob/master/src/NSwag.CodeGeneration.TypeScript/Templates/Client.ProcessResponse.HandleStatusCode.liquid

Thanks, ~Shea M