Skip to content

Commit

Permalink
Merge pull request #799 from DyfanJones/error_msg_tidy
Browse files Browse the repository at this point in the history
Error msg tidy
  • Loading branch information
DyfanJones committed Jul 5, 2024
2 parents 2681eac + 470d640 commit e8557e7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion paws.common/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ resp <- client$get_object(
Key = "<key>",
IfNoneMatch = "<etag>"
)
#> Error: SerializationError (HTTP 304). An error occurred (304) when calling the GetObject operation: Not Modified
#> Error: SerializationError (HTTP 304). An error occurred when calling the GetObject operation: Not Modified
```
* use s3 head_bucket operation as final resort when redirecting aws s3 call.

Expand Down
13 changes: 11 additions & 2 deletions paws.common/R/error.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Error <- struct(
error_response = list()
)

ERROR_MSG_TEMPLATE <- "An error occurred (%s) when calling the %s operation: %s"
ERROR_MSG_TEMPLATE <- "An error occurred when calling the %s operation%s: %s"

serialization_error <- function(request) {
error_message <- http_statuses[[
Expand All @@ -18,14 +18,23 @@ serialization_error <- function(request) {
"SerializationError",
sprintf(
ERROR_MSG_TEMPLATE,
request$http_response$status_code,
request$operation$name,
get_retry_info(request$retry_count),
error_message
),
request$http_response$status_code
)
}

get_retry_info <- function(retry_count){
if (retry_count) {
retry_msg <- sprintf(" (reached max retries: %d)", retry_count)
} else {
retry_msg <- ""
}
return(retry_msg)
}

#' Generate a classed http error
#'
#' This function generates S3 error objects which are passed to
Expand Down
2 changes: 1 addition & 1 deletion paws.common/R/retry.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ standard_retry_handler <- function(request) {
for (i in seq.int(2, exit_retries)) {
tryCatch(
{
request$retry_count <- i - 1
request <- sign(request)
if (!is.null(request[["error"]])) {
stop(aws_error(request[["error"]]))
}
request <- send(request)
request <- unmarshal_meta(request)
request <- validate_response(request)

if (!is.null(request[["error"]])) {
request <- unmarshal_error(request)
stop(aws_error(request[["error"]]))
Expand Down

0 comments on commit e8557e7

Please sign in to comment.