Skip to content

Commit 60cb9b9

Browse files
gayathrisairamGayathri Sairamkrishnan
authored and
Gayathri Sairamkrishnan
committed
Apply suggestions from code review
1 parent 5b4bf89 commit 60cb9b9

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Sources/OpenAPIRuntime/Interface/ErrorHandlingMiddleware.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import HTTPTypes
2525
/// ```swift
2626
/// extension MyAppError: HTTPResponseConvertible {
2727
/// var httpStatus: HTTPResponse.Status {
28-
/// switch self {
28+
/// switch self {
2929
/// case .invalidInputFormat:
3030
/// .badRequest
3131
/// case .authorizationError:
@@ -38,13 +38,25 @@ import HTTPTypes
3838
/// 2. Opt in to the ``ErrorHandlingMiddleware`` while registering the handler:
3939
///
4040
/// ```swift
41-
/// let handler = try await RequestHandler()
41+
/// let handler = RequestHandler()
4242
/// try handler.registerHandlers(on: transport, middlewares: [ErrorHandlingMiddleware()])
4343
/// ```
4444
/// - Note: The placement of ``ErrorHandlingMiddleware`` in the middleware chain is important.
4545
/// It should be determined based on the specific needs of each application.
4646
/// Consider the order of execution and dependencies between middlewares.
4747
public struct ErrorHandlingMiddleware: ServerMiddleware {
48+
49+
/// Creates an ErrorHandlingMiddleware.
50+
public init() {}
51+
52+
/// Intercepts an outgoing HTTP request and an incoming HTTP Response, and converts errors(if any) that confirms to ``HTTPResponseConvertible`` to an HTTP response.
53+
/// - Parameters:
54+
/// - request: The HTTP request created during the operation.
55+
/// - body: The HTTP request body created during the operation.
56+
/// - metadata: Request metadata
57+
/// - operationID: The OpenAPI operation identifier.
58+
/// - next: A closure that calls the next middleware, or the transport.
59+
/// - Returns: An HTTPResponse and an optional HTTPBody.
4860
public func intercept(
4961
_ request: HTTPTypes.HTTPRequest,
5062
body: OpenAPIRuntime.HTTPBody?,
@@ -66,14 +78,13 @@ public struct ErrorHandlingMiddleware: ServerMiddleware {
6678
}
6779
}
6880

69-
/// Protocol used by ErrorHandling middleware to map an error to a HTTPResponse.
70-
/// Adopters who wish to convert their application error to a HTTPResponse should confirm their error(s) to this protocol.
81+
/// A protocol used by ``ErrorHandlingMiddleware`` to map an error to an ``HTTPResponse`` and ``HTTPBody``.
82+
/// Adopters who wish to convert their application error to an `HTTPResponse` and ``HTTPBody`` should conform the error type to this protocol.
7183
public protocol HTTPResponseConvertible {
7284

73-
/// HTTP status to return in the response.
85+
/// An HTTP status to return in the response.
7486
var httpStatus: HTTPResponse.Status { get }
7587
/// The HTTP headers of the response.
76-
///
7788
/// This is optional as default values are provided in the extension.
7889
var httpHeaderFields: HTTPTypes.HTTPFields { get }
7990
/// The body of the HTTP response.

0 commit comments

Comments
 (0)