Skip to content

Conversation

@AlitzelMendez
Copy link
Contributor

@AlitzelMendez AlitzelMendez commented Mar 21, 2025

issue: #5361

@AlitzelMendez AlitzelMendez linked an issue Mar 21, 2025 that may be closed by this pull request
@github-actions
Copy link
Contributor

github-actions bot commented Mar 21, 2025

All changed packages have been documented.

  • @typespec/http-server-csharp
Show changes

@typespec/http-server-csharp - feature ✏️

This feature introduces changes to how error models (those using the @error decorator) are handled. Error models will now be represented as classes that extend exceptions, and when one of these custom-defined exceptions is thrown, it will produce HTTP errors as a result.,> ,> The handling of the returned status code will be resolved in the following ways:,> ,> #### If @statusCode is defined, the value of the @statusCode property will be returned,> In this case, 404 will be returned:,> tsp,> @error,> model NotFoundError{,> @statusCode _: 404,> },> ,> ,> ### If @statusCode is not defined, the error 400 will be assigned by default,> In this case, 400 will be returned:,> tsp,> @error,> model NotFoundError{,> statusCode: string;,> },> ,> ,> ### If @min and @max are defined instead of a specific value, the @min value will be returned,> In this case, 500 will be returned:,> ,> tsp,> model Standard5XXResponse {,> @minValue(500),> @maxValue(599),> @statusCode,> statusCode: int32;,> },> ,> ,> ### If @statusCode is defined as a union, the resulting model constructor will require a status code,> In this case, when the model is generated, it will require a status code to be provided:,> tsp,> model Standard4XXResponse {,> @statusCode,> statusCode: 400 | 402;,> },> ,> ,> As a result, the status code must be passed when creating an instance of the model:,> csharp ,> throw new Standard4XXResponse(400);,>

@azure-sdk
Copy link
Collaborator

azure-sdk commented Mar 21, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Copy link
Contributor

@markcowl markcowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to decide how to handle the request body in the exceptions, both how to generate it and how to customize how to create the request body.

Also need to discuss some end-to-end tests for validation, and what to add to the existing documentation we generate.

@markcowl markcowl removed the 1_0_E2E label Mar 25, 2025
@markcowl markcowl self-assigned this Mar 27, 2025
@AlitzelMendez AlitzelMendez added this pull request to the merge queue Mar 28, 2025
Merged via the queue into microsoft:main with commit b800fab Mar 28, 2025
22 checks passed
@AlitzelMendez AlitzelMendez deleted the user-defined-errors branch March 28, 2025 00:35
mario-guerra pushed a commit that referenced this pull request Apr 2, 2025
issue: #5361

---------

Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide Pattern for user-defined errors

3 participants