Skip to content

Commit

Permalink
Review comments and swift-format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gayathri Sairamkrishnan committed Dec 18, 2024
1 parent f440264 commit 52618bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
45 changes: 14 additions & 31 deletions Sources/OpenAPIRuntime/Errors/RuntimeError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,41 +142,24 @@ internal enum RuntimeError: Error, CustomStringConvertible, LocalizedError, Pret
throw RuntimeError.unexpectedResponseBody(expectedContent: expectedContent, body: body)
}

/// HTTP Response status definition for ``RuntimeError``.
/// HTTP Response status definition for ``RuntimeError``.
extension RuntimeError: HTTPResponseConvertible {
/// HTTP Status code corresponding to each error case
public var httpStatus: HTTPTypes.HTTPResponse.Status {
switch self {
case .invalidServerURL,
.invalidServerVariableValue:
.notFound
case .invalidExpectedContentType,
.missingCoderForCustomContentType,
.unexpectedContentTypeHeader:
.unsupportedMediaType
case .unexpectedAcceptHeader(_):
.notAcceptable
case .missingOrMalformedContentDispositionName:
.unprocessableContent
case .failedToDecodeStringConvertibleValue,
.invalidAcceptSubstring,
.invalidBase64String,
.invalidHeaderFieldName,
.malformedAcceptHeader,
.missingMultipartBoundaryContentTypeParameter,
.missingRequiredHeaderField,
.missingRequiredMultipartFormDataContentType,
.missingRequiredQueryParameter,
.missingRequiredPathParameter,
.missingRequiredRequestBody,
.pathUnset,
.unsupportedParameterStyle:
case .invalidServerURL, .invalidServerVariableValue: .notFound
case .invalidExpectedContentType, .unexpectedContentTypeHeader: .unsupportedMediaType
case .missingCoderForCustomContentType: .unprocessableContent
case .unexpectedAcceptHeader: .notAcceptable
case .failedToDecodeStringConvertibleValue, .invalidAcceptSubstring, .invalidBase64String,
.invalidHeaderFieldName, .malformedAcceptHeader, .missingMultipartBoundaryContentTypeParameter,
.missingOrMalformedContentDispositionName, .missingRequiredHeaderField,
.missingRequiredMultipartFormDataContentType, .missingRequiredQueryParameter, .missingRequiredPathParameter,
.missingRequiredRequestBody, .unsupportedParameterStyle:
.badRequest
case .handlerFailed,
.middlewareFailed,
.missingRequiredResponseBody,
.transportFailed,
.unexpectedResponseStatus,
.unexpectedResponseBody:
case .pathUnset: .notFound
case .handlerFailed, .middlewareFailed, .missingRequiredResponseBody, .transportFailed,
.unexpectedResponseStatus, .unexpectedResponseBody:
.internalServerError
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/OpenAPIRuntimeTests/Errors/Test_RuntimeError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import XCTest
struct MockRuntimeErrorHandler: Sendable {
var failWithError: (any Error)? = nil
func greet(_ input: String) async throws -> String {
if failWithError != nil { throw failWithError! }
if let failWithError { throw failWithError }
guard input == "hello" else { throw TestError() }
return "bye"
}
Expand Down

0 comments on commit 52618bb

Please sign in to comment.