William Cheng eb471db7c9
[R] fix a couple warnings reported by lintr (#12903)
* better code format in r client

* update code based on lintr

* update samples
2022-07-17 23:49:37 +08:00

84 lines
2.7 KiB
R

#' OpenAPI Petstore
#'
#' This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
#'
#' The version of the OpenAPI document: 1.0.0
#' Generated by: https://openapi-generator.tech
#'
#' @docType class
#' @title ApiException
#' @description ApiException Class
#' @format An \code{R6Class} generator object
#' @field status Status of the ApiException
#' @field reason Reason of the ApiException
#' @field body Body of the http response
#' @field headers Headers of the http response
#' @field errorObject error object type
#' @export
ApiException <- R6::R6Class(
"ApiException",
public = list(
status = NULL,
reason = NULL,
body = NULL,
headers = NULL,
errorObject = NULL,
#' Initialize a new ApiException class.
#'
#' @description
#' Initialize a new ApiExceptino class.
#'
#' @param status HTTP status.
#' @param reason Reason of the ApiException.
#' @param http_response HTTP response object.
#' @export
initialize = function(status = NULL, reason = NULL, http_response = NULL) {
if (!is.null(http_response)) {
self$status <- http_response$status_code
errorMsg <- toString(content(http_response))
if (errorMsg == "") {
errorMsg <- "Api exception encountered. No details given."
}
self$body <- errorMsg
self$headers <- http_response$headers
self$reason <- httr::http_status(http_response)$reason
self$errorObject <- ModelApiResponse$new()$fromJSONString(content(http_response, "text"))
} else {
self$status <- status
self$reason <- reason
self$body <- NULL
self$headers <- NULL
self$errorObject <- NULL
}
},
#' Returns the string format of ApiException.
#'
#' @description
#' Returns the string format of ApiException.
#'
#' @return the string format of ApiException.
#' @export
toString = function() {
errorMsg <- ""
errorMsg <- paste("status : ", self$status, "\n", sep = "")
errorMsg <- paste(errorMsg, "Reason : ", self$reason, "\n", sep = "")
if (!is.null(self$headers)) {
errorMsg <- paste(errorMsg, "Headers : ", "\n", sep = "")
for (name in names(self$headers)) {
errorMsg <- paste(errorMsg, name, " : ", self$headers[[name]], "\n", sep = " ")
}
}
if (!is.null(self$body)) {
errorMsg <- paste(errorMsg, "Body : ", "\n", sep = "")
errorMsg <- paste(errorMsg, self$body, "\n")
}
if (!is.null(self$errorObject)) {
errorMsg <- paste(errorMsg, "Error object : ", "\n", sep = "")
errorMsg <- paste(errorMsg, self$errorObject$toJSONString(), "\n")
}
errorMsg
}
)
)