Skip to content

Commit

Permalink
Update get_eurostat_json.R #262
Browse files Browse the repository at this point in the history
  • Loading branch information
ake123 committed Jun 19, 2023
1 parent 6614b12 commit b90e669
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions R/get_eurostat_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,23 @@ get_eurostat_json <- function(id,
# if (class(resp) == "try-error") { stop(paste("The requested url cannot be found within the get_eurostat_json function:", url)) }
resp <- httr::RETRY("GET", url, terminate_on = c(404))

status <- httr::status_code(resp)
id <- httr::content(resp)$error[[1]]$id
label_des <-httr::content(resp)$error[[1]]$label

#status <- httr::status_code(resp)
#id <- httr::content(resp)$error[[1]]$id
#label_des <-httr::content(resp)$error[[1]]$label
result <- httr::content(resp)$error
json_data_frame <- as.data.frame(result)
status <- json_data_frame$status
id <- json_data_frame$id
label <- json_data_frame$label
#print(json_data_frame)
if (httr::http_error(resp)) {
# stop(paste("The requested url cannot be found within the get_eurostat_json function:
# Client Error - 100 No results found
# Description - The requested resource is not available.", url))
#
paste("Status : ",status,
", error id : ",id,"No results found",
", label : ", label_des,"\n",
", label : ", label,"\n",
msg)
}
}
Expand All @@ -148,17 +153,21 @@ get_eurostat_json <- function(id,
jdat <- jsonlite::fromJSON(url)
} else if (status == 400) {

stop(paste("Status : ",status,"Bad request",
if(id ==100){paste(", error id : ",id , "No result found")}
else if(id ==140){paste(", error id : ",id , "Syntax error")}
else if(id ==150){paste(", error id : ",id , "Semantic error")},
", label : ", label_des,"\n",
msg))
# stop(paste("Status : ",status,"Bad request",
# if(id ==100){paste(", error id : ",id , "No result found")}
# else if(id ==140){paste(", error id : ",id , "Syntax error")}
# else if(id ==150){paste(", error id : ",id , "Semantic error")},
# ", label : ", label,"\n",
# msg))
stop(paste("Status :",status,"Bad request",
if(100 %in% id){paste(" errod id: ", id , "No result found")}
else if(140 %in% id){paste("error id: ",id , "Syntax error",)}
else if(150 %in% id){paste("errod id: ",id , "Semantic error")},label))
} else if (status == 500) {

stop(paste("Status : ",status,"Internal Server error",
", error id : ",id," Internal Server error",
", label : ", label_des),"\n",
", label : ", label),"\n",
msg)
} else if (status == 416) {
stop(
Expand All @@ -168,7 +177,9 @@ get_eurostat_json <- function(id,
)
} else {
stop(paste("Failure to get data. Status code: ",
status,
"Status : ",status,
", error id : ",id,"No results found",
", label : ", label,"\n",
msg))
}

Expand Down

0 comments on commit b90e669

Please sign in to comment.