Skip to content

Commit

Permalink
fix #121
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Feb 13, 2024
1 parent 5fadda4 commit d783f80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
- [#117](https://github.com/eblondel/ows4R/issues/117) Support pretty print of R6 objects


**Enhancements**

- [#121](https://github.com/eblondel/ows4R/issues/121) Service exceptions are not always handled in status code 400

## [ows4R 0.3-6](https://github.com/eblondel/ows4R) | [![CRAN_Status_Badge](https://img.shields.io/badge/CRAN-published-blue.svg)](https://github.com/eblondel/ows4R)

**Corrections**
Expand Down
24 changes: 16 additions & 8 deletions R/OWSHttpRequest.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,27 @@ OWSHttpRequest <- R6Class("OWSHttpRequest",
private$response <- req$response

#exception handling
if(private$status != 200){ #usually a status code 400
xmlObj = req$response
#service exception is usually returned with a status code 400 but not always!
if(is.vector(req$response)){
exception_tmp_file = tempfile(fileext = ".xml")
writeBin(req$response, exception_tmp_file)
xmlObj = try(XML::xmlParse(exception_tmp_file), silent = TRUE)
if(!is(xmlObj, "try-error")) if(!is.null(xmlNamespaces(xmlObj)$ows)){
exception <- getNodeSet(xmlObj, "//ows:Exception", c(ows = xmlNamespaces(xmlObj)$ows$uri))
if(length(exception)>0){
exception <- OWSException$new(xmlObj = exception[[1]])
}
if(!is(xmlObj, "try-error")) if(!is.null(xmlNamespaces(xmlObj)$ows)){
exception <- getNodeSet(xmlObj, "//ows:Exception", c(ows = xmlNamespaces(xmlObj)$ows$uri))
if(length(exception)>0){
exception <- OWSException$new(xmlObj = exception[[1]])
if(!is.null(exception$getLocator()) & !is.null(exception$getCode())){
self$ERROR(sprintf("Exception [locator:'%s' code:'%s']: %s", exception$getLocator(), exception$getCode(), exception$getText()))
private$exception <- exception
private$response <- NULL
self$setResult(FALSE)
}else{
self$ERROR(sprintf("Exception: %s", exception$getText()))
}
private$exception <- exception
private$response <- NULL
self$setResult(FALSE)
}else{
self$setResult(TRUE)
}
}else{
self$setResult(TRUE)
Expand Down

0 comments on commit d783f80

Please sign in to comment.