jcpsantiago / sentryR

Unofficial R client for Sentry
https://jcpsantiago.github.io/sentryR/
Other
38 stars 14 forks source link

Error connecting to Sentry:{"error":"No JSON data was found"} #2

Closed ndiquattro closed 4 years ago

ndiquattro commented 5 years ago

Hello, thanks for working on this package! I was trying to set it up and I'm running into this error when I make a request to my plumber API that intentionally creates an error:

Warning in sentryR::sentry.captureException(err, req) :
  Error connecting to Sentry:{"error":"No JSON data was found"}

Looking around, it seems like this is relevant: https://github.com/getsentry/sentry/issues/6978

But, not sure how to apply it to my issue. Thanks!

jcpsantiago commented 5 years ago

Thanks for trying it out! I have not encountered such an error so far, could you provide a minimal example?

ndiquattro commented 5 years ago

It looks the issue was I wasn't setting a content type in my test requests from httr. The NULL value in req$HTTP_CONTENT_TYPE was causing glue to fail here: https://github.com/ozean12/sentryR/blob/master/R/sentry.R#L82-L106 .

There seems to be a similar issue where not having req$postBody available (e.g. in a GET) causes an error here: https://github.com/ozean12/sentryR/blob/master/R/sentry.R#L75-L78 . It causes this error:

Error: lexical error: invalid char in json text.
                                       NA
                     (right here) ------^

Of course, I may be making a different type of mistake in my request :)

jcpsantiago commented 5 years ago

humm seems like we did some hard assumptions there. I can reproduce the error with

#* @get /error
api.error <- withCapturedCalls(function(res, req){
  stop('error')
})

I'll add some default "null" values in cases where those are not set, which is ok because those vars are not critical. I'll test it later and see if it fixes the issue

jcpsantiago commented 4 years ago

@ndiquattro could you check if the latest PR fixed your issue? I'm writing some tests currently