From c5987e33b094fa985e4abe65f0e56920ead67d60 Mon Sep 17 00:00:00 2001 From: Scott Chamberlain Date: Mon, 27 Jan 2020 11:54:52 -0800 Subject: [PATCH] fix #14 - fix internal error message parsingn to account for changes in MAS error formats --- DESCRIPTION | 2 +- R/zzz.R | 30 ++++++++++++--- tests/fixtures/ma_error.yml | 65 ++++++++++++++++++++++++++++++-- tests/testthat/test-error-msgs.R | 10 ++++- 4 files changed, 97 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index add1d6e..5fa27e7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -6,7 +6,7 @@ Description: The 'Microsoft Academic Knowledge' API provides programmatic access (). Includes methods matching all 'Microsoft Academic' API routes, including search, graph search, text similarity, and interpret natural language query string. -Version: 0.4.3.94 +Version: 0.4.4.91 Authors@R: c( person("Scott", "Chamberlain", email = "myrmecocystus+r@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-1444-9135")), diff --git a/R/zzz.R b/R/zzz.R index 502712c..f1d2c2a 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -66,14 +66,34 @@ raise_for_status2 <- function(res) { parse_error_msg <- function(res) { txt <- res$parse("UTF-8") - er_vec <- unlist(jsonlite::fromJSON(txt)) + er_vec <- jsonlite::fromJSON(txt) + er_vec <- all_to_lower(er_vec) # er_vec names used to be capitilized (e.g., "Error.Code", not "error.code"). # convert to lowercase just in case API goes back to using caps. - names(er_vec) <- tolower(names(er_vec)) - list( + # names(er_vec) <- tolower(names(er_vec)) + tmp <- list( # the error.code element refers to a short error message, not the HTTP # status code - message = er_vec[["error.code"]], - explanation = er_vec[["error.message"]] + message = er_vec$error$code, + explanation = er_vec$error$message ) + if (!is.null(er_vec$error$innererrors)) { + tmp$explanation <- er_vec$error$innererrors$message[1] + } + return(tmp) +} + +# x = list(A = list(B = 6), C = list(D = 7, E = list(F = list(G = 7)))) +# all_to_lower(x) +all_to_lower <- function(x) { + if (!is.null(names(x))) { + names(x) <- tolower(names(x)) + } + if (is.list(x)) { + x <- lapply(x, all_to_lower) + } + if (is.data.frame(x)) { + names(x) <- tolower(names(x)) + } + x } diff --git a/tests/fixtures/ma_error.yml b/tests/fixtures/ma_error.yml index b139779..e601ecd 100644 --- a/tests/fixtures/ma_error.yml +++ b/tests/fixtures/ma_error.yml @@ -23,10 +23,69 @@ http_interactions: request-context: appId=cid-v1:8d5cbad1-6ca8-4d39-8271-8f3a8d671eae access-control-expose-headers: Request-Context x-powered-by: ASP.NET - date: Mon, 27 Jan 2020 19:49:57 GMT + date: Mon, 27 Jan 2020 19:53:50 GMT body: encoding: ASCII-8BIT file: no - string: eyJFcnJvciI6eyJJZCI6IjUxZTllZGU2LTY1MTktNDQyNC04NjZiLTliM2EyNTZlZjhiMCIsIkNvZGUiOiJTeXN0ZW0uQWdncmVnYXRlRXhjZXB0aW9uIiwiTWVzc2FnZSI6Ik9uZSBvciBtb3JlIGVycm9ycyBvY2N1cnJlZC4iLCJUYXJnZXQiOiJLbm93bGVkZ2VFeHBsb3JhdGlvblNlcnZpY2VIb3N0IiwiSW5uZXJFcnJvcnMiOlt7IklkIjoiMGNiZGVmNDgtM2M0MS00MDQ5LWIzZDEtNWJhYTIwMTliNzUxIiwiQ29kZSI6IlN5c3RlbS5Bcmd1bWVudEV4Y2VwdGlvbiIsIk1lc3NhZ2UiOiJRdWVyeSBwYXJzaW5nIGVycm9yIGluIHN0cmluZyBcImhpLXRoZXJlXCIgYXQgcG9zaXRpb24gMjogVW5rbm93biBmdW5jdGlvbi9hdHRyaWJ1dGUgJ2hpJyJ9LHsiSWQiOiI4YjVlNGFmOC1jYjViLTQwYmUtOTJlMi00ZTBkMTcxNjUzODEiLCJDb2RlIjoiU3lzdGVtLkFyZ3VtZW50RXhjZXB0aW9uIiwiTWVzc2FnZSI6IlF1ZXJ5IHBhcnNpbmcgZXJyb3IgaW4gc3RyaW5nIFwiaGktdGhlcmVcIiBhdCBwb3NpdGlvbiAyOiBVbmtub3duIGZ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lICdoaScifSx7IklkIjoiZmFlY2M0MzEtOGQzYy00MzcyLTlhOGEtMWU1ZDdhNjdmOGFhIiwiQ29kZSI6IlN5c3RlbS5Bcmd1bWVudEV4Y2VwdGlvbiIsIk1lc3NhZ2UiOiJRdWVyeSBwYXJzaW5nIGVycm9yIGluIHN0cmluZyBcImhpLXRoZXJlXCIgYXQgcG9zaXRpb24gMjogVW5rbm93biBmdW5jdGlvbi9hdHRyaWJ1dGUgJ2hpJyJ9XX19 + recorded_at: 2020-01-27 19:53:51 GMT + recorded_with: vcr/0.4.0, webmockr/0.5.0 +- request: + method: get + uri: https://api.labs.cognitive.microsoft.com/academic/v1.0/evaluate?expr=Y%3D%5B2010%2C%202012%29&count=10&offset=bad-offset&attributes=Id%2CAA.AuN%2CJ.JN%2CTi%2CY%2CE%2CCC&model=latest + body: + encoding: '' + string: '' + headers: + User-Agent: libcurl/7.54.0 r-curl/4.3 crul/0.9.0 + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + Ocp-Apim-Subscription-Key: <<>> + response: + status: + status_code: '400' + message: Bad Request + explanation: Bad request syntax or unsupported method + headers: + status: HTTP/1.1 400 Bad Request + content-length: '265' + content-type: application/json + access-control-allow-origin: '*' + request-context: appId=cid-v1:8d5cbad1-6ca8-4d39-8271-8f3a8d671eae + access-control-expose-headers: Request-Context + x-powered-by: ASP.NET + date: Mon, 27 Jan 2020 19:53:50 GMT + body: + encoding: ASCII-8BIT + file: no + string: eyJFcnJvciI6eyJJZCI6IjViYzgyNWQ1LWY4ZjQtNDE1OS04OGUxLTgzMGQyZjJiOTNlOSIsIkNvZGUiOiJTeXN0ZW0uQWdncmVnYXRlRXhjZXB0aW9uIiwiTWVzc2FnZSI6Ik9uZSBvciBtb3JlIGVycm9ycyBvY2N1cnJlZC4iLCJJbm5lckVycm9ycyI6W3siSWQiOiJkMGMyNWVkOC02OGE1LTQyZjMtYTVmNi05YjYwYTliYmIyZTIiLCJDb2RlIjoiU3lzdGVtLkFyZ3VtZW50RXhjZXB0aW9uIiwiTWVzc2FnZSI6Ik9mZnNldCBtdXN0IGJlIGFuIGludGVnZXIifV19fQ== + recorded_at: 2020-01-27 19:53:51 GMT + recorded_with: vcr/0.4.0, webmockr/0.5.0 +- request: + method: get + uri: https://api.labs.cognitive.microsoft.com/academic/v1.0/evaluate?expr=Y%3D%5B2010%2C%202012%29&count=10&offset=0&attributes=Id%2CAA.AuN%2CJ.JN%2CTi%2CY%2CE%2CCC&model=latest + body: + encoding: '' + string: '' + headers: + User-Agent: libcurl/7.54.0 r-curl/4.3 crul/0.9.0 + Accept-Encoding: gzip, deflate + Accept: application/json, text/xml, application/xml, */* + Ocp-Apim-Subscription-Key: bad-key + response: + status: + status_code: '401' + message: Unauthorized + explanation: No permission -- see authorization schemes + headers: + status: HTTP/1.1 401 Access Denied + content-length: '180' + content-type: application/json + www-authenticate: AzureApiManagementKey realm="https://api.labs.cognitive.microsoft.com/academic/v1.0",name="Ocp-Apim-Subscription-Key",type="header" + date: Mon, 27 Jan 2020 19:53:50 GMT + body: + encoding: ASCII-8BIT + file: no + string: eyJlcnJvciI6eyJjb2RlIjoiVW5zcGVjaWZpZWQiLCJtZXNzYWdlIjoiQWNjZXNzIGRlbmllZCBkdWUgdG8gaW52YWxpZCBzdWJzY3JpcHRpb24ga2V5LiBNYWtlIHN1cmUgeW91IGFyZSBzdWJzY3JpYmVkIHRvIGFuIEFQSSB5b3UgYXJlIHRyeWluZyB0byBjYWxsIGFuZCBwcm92aWRlIHRoZSByaWdodCBrZXkuIn19 + recorded_at: 2020-01-27 19:53:51 GMT recorded_with: vcr/0.4.0, webmockr/0.5.0 diff --git a/tests/testthat/test-error-msgs.R b/tests/testthat/test-error-msgs.R index 6fecc31..0c92a78 100644 --- a/tests/testthat/test-error-msgs.R +++ b/tests/testthat/test-error-msgs.R @@ -4,6 +4,14 @@ test_that("Detailed error messages are provided when possible", { skip_on_cran() vcr::use_cassette("ma_error", { - expect_error(ma_search(query = "hi-there")) + # error: Query parsing error in string "hi-there" at position 2: Unknown + # function/attribute 'hi' + expect_error(ma_search("hi-there")) + # error: Offset must be an integer + expect_error(ma_evaluate("Y=[2010, 2012)", offset = "bad-offset")) + # error: Access denied due to invalid subscription key. Make sure you + # are subscribed to an API you are trying to call and provide the right + # key. + expect_error(ma_search("Y=[2010, 2012)", key = "bad-key")) }, preserve_exact_body_bytes = TRUE) })