Skip to content

Commit 52618bb

Browse files
author
Gayathri Sairamkrishnan
committed
Review comments and swift-format changes
1 parent f440264 commit 52618bb

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

Sources/OpenAPIRuntime/Errors/RuntimeError.swift

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -142,41 +142,24 @@ internal enum RuntimeError: Error, CustomStringConvertible, LocalizedError, Pret
142142
throw RuntimeError.unexpectedResponseBody(expectedContent: expectedContent, body: body)
143143
}
144144

145-
/// HTTP Response status definition for ``RuntimeError``.
145+
/// HTTP Response status definition for ``RuntimeError``.
146146
extension RuntimeError: HTTPResponseConvertible {
147+
/// HTTP Status code corresponding to each error case
147148
public var httpStatus: HTTPTypes.HTTPResponse.Status {
148149
switch self {
149-
case .invalidServerURL,
150-
.invalidServerVariableValue:
151-
.notFound
152-
case .invalidExpectedContentType,
153-
.missingCoderForCustomContentType,
154-
.unexpectedContentTypeHeader:
155-
.unsupportedMediaType
156-
case .unexpectedAcceptHeader(_):
157-
.notAcceptable
158-
case .missingOrMalformedContentDispositionName:
159-
.unprocessableContent
160-
case .failedToDecodeStringConvertibleValue,
161-
.invalidAcceptSubstring,
162-
.invalidBase64String,
163-
.invalidHeaderFieldName,
164-
.malformedAcceptHeader,
165-
.missingMultipartBoundaryContentTypeParameter,
166-
.missingRequiredHeaderField,
167-
.missingRequiredMultipartFormDataContentType,
168-
.missingRequiredQueryParameter,
169-
.missingRequiredPathParameter,
170-
.missingRequiredRequestBody,
171-
.pathUnset,
172-
.unsupportedParameterStyle:
150+
case .invalidServerURL, .invalidServerVariableValue: .notFound
151+
case .invalidExpectedContentType, .unexpectedContentTypeHeader: .unsupportedMediaType
152+
case .missingCoderForCustomContentType: .unprocessableContent
153+
case .unexpectedAcceptHeader: .notAcceptable
154+
case .failedToDecodeStringConvertibleValue, .invalidAcceptSubstring, .invalidBase64String,
155+
.invalidHeaderFieldName, .malformedAcceptHeader, .missingMultipartBoundaryContentTypeParameter,
156+
.missingOrMalformedContentDispositionName, .missingRequiredHeaderField,
157+
.missingRequiredMultipartFormDataContentType, .missingRequiredQueryParameter, .missingRequiredPathParameter,
158+
.missingRequiredRequestBody, .unsupportedParameterStyle:
173159
.badRequest
174-
case .handlerFailed,
175-
.middlewareFailed,
176-
.missingRequiredResponseBody,
177-
.transportFailed,
178-
.unexpectedResponseStatus,
179-
.unexpectedResponseBody:
160+
case .pathUnset: .notFound
161+
case .handlerFailed, .middlewareFailed, .missingRequiredResponseBody, .transportFailed,
162+
.unexpectedResponseStatus, .unexpectedResponseBody:
180163
.internalServerError
181164
}
182165
}

Tests/OpenAPIRuntimeTests/Errors/Test_RuntimeError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import XCTest
1919
struct MockRuntimeErrorHandler: Sendable {
2020
var failWithError: (any Error)? = nil
2121
func greet(_ input: String) async throws -> String {
22-
if failWithError != nil { throw failWithError! }
22+
if let failWithError { throw failWithError }
2323
guard input == "hello" else { throw TestError() }
2424
return "bye"
2525
}

0 commit comments

Comments
 (0)