From 52618bb31d5294d8fa570ad04a45afd38508f060 Mon Sep 17 00:00:00 2001 From: Gayathri Sairamkrishnan Date: Wed, 18 Dec 2024 11:24:00 +0000 Subject: [PATCH] Review comments and swift-format changes --- .../OpenAPIRuntime/Errors/RuntimeError.swift | 45 ++++++------------- .../Errors/Test_RuntimeError.swift | 2 +- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/Sources/OpenAPIRuntime/Errors/RuntimeError.swift b/Sources/OpenAPIRuntime/Errors/RuntimeError.swift index e2ed3f21..7923dd05 100644 --- a/Sources/OpenAPIRuntime/Errors/RuntimeError.swift +++ b/Sources/OpenAPIRuntime/Errors/RuntimeError.swift @@ -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 } } diff --git a/Tests/OpenAPIRuntimeTests/Errors/Test_RuntimeError.swift b/Tests/OpenAPIRuntimeTests/Errors/Test_RuntimeError.swift index cf41627b..f606e3be 100644 --- a/Tests/OpenAPIRuntimeTests/Errors/Test_RuntimeError.swift +++ b/Tests/OpenAPIRuntimeTests/Errors/Test_RuntimeError.swift @@ -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" }