Skip to content

Commit

Permalink
improved OANDA error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Oct 27, 2023
1 parent c2a3b8e commit ee0a1b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ichimoku 1.4.9.9000 (development)

* Improved handling for OANDA API errors.

# ichimoku 1.4.9

* Internal performance enhancements.
Expand Down
11 changes: 6 additions & 5 deletions R/switch.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ do_ <- function() {
resp <- ncurl(url, convert = FALSE, follow = TRUE,
headers = c("Authorization" = paste0("Bearer ", apikey),
"User-Agent" = .user_agent))
resp[["status"]] == 200L ||
stop("status code ", resp[["status"]], " - ",
deserialize_json(resp[["data"]]), call. = FALSE)
parsed <- deserialize_json(resp[["data"]])
length(parsed[["accounts"]]) || stop(parsed, call. = FALSE)
account <<- parsed[["accounts"]][[1L]][["id"]]
Expand All @@ -137,11 +140,9 @@ do_ <- function() {
resp <- ncurl(url, convert = FALSE, follow = TRUE,
headers = c("Authorization" = paste0("Bearer ", apikey),
"User-Agent" = .user_agent))
if (resp[["status"]] != 200L) {
resp <- ncurl(url, convert = FALSE, follow = TRUE,
headers = c("Authorization" = paste0("Bearer ", apikey),
"User-Agent" = .user_agent))
}
resp[["status"]] == 200L ||
stop("status code ", resp[["status"]], " - ",
deserialize_json(resp[["data"]]), call. = FALSE)
parsed <- deserialize_json(resp[["data"]])
length(parsed[["instruments"]]) || {
warning(parsed,
Expand Down

0 comments on commit ee0a1b8

Please sign in to comment.