Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Sources/YData/Client/InternalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion Sources/YData/Client/InternalResponse+Vapor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public extension ClientResponse {
func mapToModel<C>() throws -> C where C: Decodable {
switch status.code {
case (100..<400):

do {
return try content.decode(C.self)
} catch {
Expand All @@ -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,
Expand Down