Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Consider passing along detailed error messages to user #7

Closed
crew102 opened this issue Jan 7, 2019 · 1 comment
Closed

Consider passing along detailed error messages to user #7

crew102 opened this issue Jan 7, 2019 · 1 comment
Milestone

Comments

@crew102
Copy link
Collaborator

crew102 commented Jan 7, 2019

It would be nice if microdemic passed along the detailed error messages that the API provides, as opposed to just giving the HTTP error code. For example:

library(microdemic)
library(httr)

# here we only get the HTTP error code
ma_evaluate(
  query = "invalid-query", 
  key = Sys.getenv("MAG_KEY")
)
#> Error: Bad Request (HTTP 400)

# ...but the server provides more details on why this error occured:
out <- POST(
  'https://api.labs.cognitive.microsoft.com/academic/v1.0/evaluate',
  config = add_headers("Ocp-Apim-Subscription-Key" = Sys.getenv("MAG_KEY")),
  body = "expr=invalid-query"
)
content(out, "text")
#> No encoding supplied: defaulting to UTF-8.
#> [1] "{\"Error\":{\"Code\":\"Bad Argument\",\"Message\":\"Invalid query expression\\r\\nParameter name: expression\"}}"

Created on 2019-01-07 by the reprex package (v0.2.0.9000).

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.4 (2018-03-15)
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2019-01-07
#> Packages -----------------------------------------------------------------
#>  package    * version date       source         
#>  backports    1.1.2   2017-12-13 cran (@1.1.2)  
#>  base       * 3.4.4   2018-03-16 local          
#>  compiler     3.4.4   2018-03-16 local          
#>  crul         0.7.0   2019-01-04 CRAN (R 3.4.4) 
#>  curl         3.2     2018-03-28 CRAN (R 3.4.4) 
#>  datasets   * 3.4.4   2018-03-16 local          
#>  devtools     1.13.6  2018-06-27 cran (@1.13.6) 
#>  digest       0.6.17  2018-09-12 cran (@0.6.17) 
#>  evaluate     0.10.1  2017-06-24 cran (@0.10.1) 
#>  graphics   * 3.4.4   2018-03-16 local          
#>  grDevices  * 3.4.4   2018-03-16 local          
#>  htmltools    0.3.6   2017-04-28 cran (@0.3.6)  
#>  httpcode     0.2.0   2016-11-14 CRAN (R 3.4.4) 
#>  httr       * 1.3.1   2017-08-20 CRAN (R 3.4.4) 
#>  knitr        1.20    2018-02-20 cran (@1.20)   
#>  magrittr     1.5     2014-11-22 cran (@1.5)    
#>  memoise      1.1.0   2017-04-21 CRAN (R 3.4.4) 
#>  methods    * 3.4.4   2018-03-16 local          
#>  microdemic * 0.4.0   2018-10-25 CRAN (R 3.4.4) 
#>  pillar       1.2.3   2018-05-25 cran (@1.2.3)  
#>  R6           2.2.2   2017-06-17 cran (@2.2.2)  
#>  Rcpp         0.12.18 2018-07-23 cran (@0.12.18)
#>  rlang        0.2.2   2018-08-16 cran (@0.2.2)  
#>  rmarkdown    1.10    2018-06-11 cran (@1.10)   
#>  rprojroot    1.3-2   2018-01-03 cran (@1.3-2)  
#>  stats      * 3.4.4   2018-03-16 local          
#>  stringi      1.2.4   2018-07-20 cran (@1.2.4)  
#>  stringr      1.3.1   2018-05-10 cran (@1.3.1)  
#>  tibble       1.4.2   2018-01-22 cran (@1.4.2)  
#>  tools        3.4.4   2018-03-16 local          
#>  triebeard    0.3.0   2016-08-04 CRAN (R 3.4.4) 
#>  urltools     1.7.1   2018-08-03 CRAN (R 3.4.4) 
#>  utils      * 3.4.4   2018-03-16 local          
#>  withr        2.1.2   2018-03-15 CRAN (R 3.4.4) 
#>  yaml         2.2.0   2018-07-25 cran (@2.2.0)

Happy to create a PR for this if you're interested.

@sckott
Copy link
Contributor

sckott commented Jan 7, 2019

thanks for raising the issue. thanks for offering to PR! Please do use crul instead of httr.

Adding this will need to make sure it's comprehensive, e.g., its possible they don't fail consistently so you can't always look for that json payload on failure. I dont remember if their failure behavior is consistent or not. Please do add tests

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants