Skip to content

Commit

Permalink
Remove error handling from API wrapper functions, put in other functions
Browse files Browse the repository at this point in the history
  • Loading branch information
afwillia committed Feb 20, 2024
1 parent 1cfe292 commit 4060509
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
29 changes: 14 additions & 15 deletions R/schematic_rest_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
schema_url="https://raw.githubusercontent.com/ncihtan/data-models/main/HTAN.model.jsonld", #nolint
data_type, file_name = NULL, restrict_rules=FALSE, project_scope = NULL,
access_token, asset_view = NULL, json_str = NULL) {
a <- paste0(sample(1000, 1), "-")
flattenbody <- function(x) {
# A form/query can only have one value per name, so take
# any values that contain vectors length >1 and
Expand Down Expand Up @@ -177,20 +176,20 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
}

# Format server error in a way validationResult can handle
if (httr2::resp_is_error(resp)) {
return(
list(
list(
"errors" = list(
Row = NA, Column = NA, Value = NA,
Error = sprintf("Cannot validate manifest: %s",
httr2::resp_status_desc(resp)
)
)
)
)
)
}
# if (httr2::resp_is_error(resp)) {
# return(
# list(
# list(
# "errors" = list(
# Row = NA, Column = NA, Value = NA,
# Error = sprintf("Cannot validate manifest: %s",
# httr2::resp_status_desc(resp)
# )
# )
# )
# )
# )
# }
httr2::resp_body_json(resp)
}

Expand Down
29 changes: 14 additions & 15 deletions functions/schematic_rest_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
schema_url="https://raw.githubusercontent.com/ncihtan/data-models/main/HTAN.model.jsonld", #nolint
data_type, file_name = NULL, restrict_rules=FALSE, project_scope = NULL,
access_token, asset_view = NULL, json_str = NULL) {
a <- paste0(sample(1000, 1), "-")
flattenbody <- function(x) {
# A form/query can only have one value per name, so take
# any values that contain vectors length >1 and
Expand Down Expand Up @@ -177,20 +176,20 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
}

# Format server error in a way validationResult can handle
if (httr2::resp_is_error(resp)) {
return(
list(
list(
"errors" = list(
Row = NA, Column = NA, Value = NA,
Error = sprintf("Cannot validate manifest: %s",
httr2::resp_status_desc(resp)
)
)
)
)
)
}
# if (httr2::resp_is_error(resp)) {
# return(
# list(
# list(
# "errors" = list(
# Row = NA, Column = NA, Value = NA,
# Error = sprintf("Cannot validate manifest: %s",
# httr2::resp_status_desc(resp)
# )
# )
# )
# )
# )
# }
httr2::resp_body_json(resp)
}

Expand Down

0 comments on commit 4060509

Please sign in to comment.