forked from loafle/openapi-generator-original
[R] improve binary/text response handling (#20131)
* [R client] better support for binary/compressed responses * cleanup * revert change after PR review * update samples * fix R tests * move private api methods to api-client, revert breaking method name change
This commit is contained in:
@@ -66,13 +66,13 @@ PathApi <- R6::R6Class(
|
||||
TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath = function(path_string, path_integer, enum_nonref_string_path, enum_ref_string_path, data_file = NULL, ...) {
|
||||
local_var_response <- self$TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathWithHttpInfo(path_string, path_integer, enum_nonref_string_path, enum_ref_string_path, data_file = data_file, ...)
|
||||
if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
|
||||
local_var_response$content
|
||||
return(local_var_response$content)
|
||||
} else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
|
||||
local_var_response
|
||||
return(local_var_response)
|
||||
} else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
|
||||
local_var_response
|
||||
return(local_var_response)
|
||||
} else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
|
||||
local_var_response
|
||||
return(local_var_response)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -157,18 +157,21 @@ PathApi <- R6::R6Class(
|
||||
if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
|
||||
# save response in a file
|
||||
if (!is.null(data_file)) {
|
||||
write(local_var_resp$response, data_file)
|
||||
self$api_client$WriteFile(local_var_resp, data_file)
|
||||
}
|
||||
|
||||
deserialized_resp_obj <- tryCatch(
|
||||
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
|
||||
self$api_client$DeserializeResponse(local_var_resp, "character"),
|
||||
error = function(e) {
|
||||
stop("Failed to deserialize response")
|
||||
}
|
||||
)
|
||||
local_var_resp$content <- deserialized_resp_obj
|
||||
local_var_resp
|
||||
} else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
|
||||
return(local_var_resp)
|
||||
}
|
||||
|
||||
local_var_error_msg <- local_var_resp$response_as_text()
|
||||
if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
|
||||
ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
|
||||
} else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
|
||||
ApiResponse$new("API client error", local_var_resp)
|
||||
@@ -176,7 +179,7 @@ PathApi <- R6::R6Class(
|
||||
if (is.null(local_var_resp$response) || local_var_resp$response == "") {
|
||||
local_var_resp$response <- "API server error"
|
||||
}
|
||||
local_var_resp
|
||||
return(local_var_resp)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user