diff --git a/paws.common/DESCRIPTION b/paws.common/DESCRIPTION index 4f46e9e70..7e7c2e9d2 100644 --- a/paws.common/DESCRIPTION +++ b/paws.common/DESCRIPTION @@ -62,11 +62,11 @@ Collate: 'custom_dynamodb.R' 'custom_rds.R' 'http_status.R' + 'error.R' 'tags.R' 'xmlutil.R' 'stream.R' 'custom_s3.R' - 'error.R' 'handlers_core.R' 'handlers_ec2query.R' 'handlers_jsonrpc.R' diff --git a/paws.common/R/custom_s3.R b/paws.common/R/custom_s3.R index de06e4572..9fbe285ca 100644 --- a/paws.common/R/custom_s3.R +++ b/paws.common/R/custom_s3.R @@ -1,7 +1,7 @@ #' @include service.R #' @include stream.R #' @include util.R -#' @include http_status.R +#' @include error.R NULL ################################################################################ @@ -281,13 +281,7 @@ s3_unmarshal_error <- function(request) { return(request) } if (is.null(data)) { - msg <- "An error occurred (%s) when calling the %s operation: %s" - error_message <- http_statuses[as.character(request$http_response$status_code)] - request$error <- Error( - "SerializationError", - sprintf(msg, request$http_response$status_code, request$operation$name, error_message), - request$http_response$status_code - ) + request$error <- serialization_error(request) return(request) } @@ -296,11 +290,7 @@ s3_unmarshal_error <- function(request) { message <- error_response$Message if (is.null(message) && is.null(code)) { - request$error <- Error( - "SerializationError", - "failed to decode query XML error response", - request$http_response$status_code - ) + request$error <- serialization_error(request) return(request) } diff --git a/paws.common/R/error.R b/paws.common/R/error.R index 564ada864..e69269dc6 100644 --- a/paws.common/R/error.R +++ b/paws.common/R/error.R @@ -1,3 +1,5 @@ +#' @include http_status.R + # Returns an Error object. Error <- struct( code = "", @@ -6,6 +8,24 @@ Error <- struct( error_response = list() ) +ERROR_MSG_TEMPLATE <- "An error occurred (%s) when calling the %s operation: %s" + +serialization_error <- function(request) { + error_message <- http_statuses[ + as.character(request$http_response$status_code) + ] + Error( + "SerializationError", + sprintf( + ERROR_MSG_TEMPLATE, + request$http_response$status_code, + request$operation$name, + error_message + ), + request$http_response$status_code + ) +} + #' Generate a classed http error #' #' This function generates S3 error objects which are passed to diff --git a/paws.common/R/handlers_query.R b/paws.common/R/handlers_query.R index 916e53384..9e9779ead 100644 --- a/paws.common/R/handlers_query.R +++ b/paws.common/R/handlers_query.R @@ -1,4 +1,4 @@ -#' @include http_status.R +#' @include error.R # Build the request for the Query protocol. query_build <- function(request) { @@ -47,13 +47,7 @@ query_unmarshal_error <- function(request) { ) if (is.null(data)) { - msg <- "An error occurred (%s) when calling the %s operation: %s" - error_message <- http_statuses[as.character(request$http_response$status_code)] - request$error <- Error( - "SerializationError", - sprintf(msg, request$http_response$status_code, request$operation$name, error_message), - request$http_response$status_code - ) + request$error <- serialization_error(request) return(request) } @@ -63,11 +57,7 @@ query_unmarshal_error <- function(request) { ) if (is.null(error)) { - request$error <- Error( - "SerializationError", - "failed to decode query XML error response", - request$http_response$status_code - ) + request$error <- serialization_error(request) return(request) }