You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Replace the proposed solution to have a single error handling protocol, with the status being required and
17
+
headers/body being optional.
13
18
14
19
### Introduction
15
20
@@ -18,7 +23,8 @@ introduces a way for users to map errors thrown by their handlers to specific HT
18
23
19
24
### Motivation
20
25
21
-
When implementing a server with Swift OpenAPI Generator, users implement a type that conforms to a generated protocol, providing one method for each API operation defined in the OpenAPI document. At runtime, if this function throws, it's up to the server transport to transform it into an HTTP response status code – for example, some transport use `500 Internal Error`.
26
+
When implementing a server with Swift OpenAPI Generator, users implement a type that conforms to a generated protocol,
27
+
providing one method for each API operation defined in the OpenAPI document. At runtime, if this function throws, it's up to the server transport to transform it into an HTTP response status code – for example, some transport use `500 Internal Error`.
22
28
23
29
Instead, server developers may want to map errors thrown by the application to a more specific HTTP response.
24
30
Currently, this can be achieved by checking for each error type in each handler's catch block, converting it to an
@@ -46,7 +52,7 @@ If a user wishes to map many errors, the error handling block scales linearly an
46
52
47
53
The proposed solution is twofold.
48
54
49
-
1. Provide protocol(s) in `OpenAPIRuntime` to allow users to extend their error types with mappings to HTTP responses.
55
+
1. Provide a protocol in `OpenAPIRuntime` to allow users to extend their error types with mappings to HTTP responses.
50
56
51
57
2. Provide an (opt-in) middleware in OpenAPIRuntime that will call the conversion function on conforming error types when
52
58
constructing the HTTP response.
@@ -62,20 +68,19 @@ The proposal aims to provide a transport agnostic error handling mechanism for O
62
68
63
69
#### Proposed Error protocols
64
70
65
-
Users can choose to conform to one of the protocols described below depending on the level of specificity they would
66
-
like to have in the response.
71
+
Users can choose to conform to the error handling protocol below and optionally provide the optional fields depending on
72
+
the level of specificity they would like to have in the response.
0 commit comments