diff --git a/Sources/YData/Client/InternalClient.swift b/Sources/YData/Client/InternalClient.swift index 6fb7fbb..91a277f 100644 --- a/Sources/YData/Client/InternalClient.swift +++ b/Sources/YData/Client/InternalClient.swift @@ -69,6 +69,17 @@ private extension EventLoopFuture where Value: InternalResponse { return .failure(Internal.ErrorResponse(headers: response.headers, status: response.status, message:contentError.message)) + } catch DecodingError.keyNotFound { + do { + let contentError = try response.content.decode(String.self) + return .failure(Internal.ErrorResponse(headers: response.headers, + status: response.status, + message: contentError)) + } catch { + return .failure(Internal.ErrorResponse(headers: [:], + status: .internalServerError, + message: "failed to decode response with error \(error)")) + } } catch { return .failure(Internal.ErrorResponse(headers: [:], status: .internalServerError, diff --git a/Sources/YData/Client/InternalResponse+Vapor.swift b/Sources/YData/Client/InternalResponse+Vapor.swift index 73bfec9..3396855 100644 --- a/Sources/YData/Client/InternalResponse+Vapor.swift +++ b/Sources/YData/Client/InternalResponse+Vapor.swift @@ -54,7 +54,6 @@ public extension ClientResponse { func mapToModel() throws -> C where C: Decodable { switch status.code { case (100..<400): - do { return try content.decode(C.self) } catch { @@ -68,6 +67,11 @@ public extension ClientResponse { throw Internal.ErrorResponse(headers: headers, status: status, message:contentError.message) + } catch DecodingError.keyNotFound { + let contentError = try content.decode(String.self) + throw Internal.ErrorResponse(headers: headers, + status: status, + message: contentError) } catch { throw Internal.ErrorResponse(headers: [:], status: .internalServerError,