Skip to main content
Solved

Getting error when trying to parse Webhook response [Sandbox] - "Converting circular structure to JSON"

  • 18 March 2022
  • 1 reply
  • 261 views

Hi RevenueCat
I’ve got a trouble with adding webhook support to our backend, right now we’re receiving test webhook event but when we are doing parsing we’re getting such error "Converting circular structure to JSON"
this error comes from library that we’re using to parse cookies (‘cookie-parser’)

as an example that is what we get from your side and in the request we have a number of Circular objects references which couldn’t be parsed by javascript properly, can you explain why it happens and how should we handle this 

{"req":{"socket":{"_pendingData":null,"_parent":null,"bytesRead":2222,"remotePort":16134,"connecting":false,"_server":""Circular]","_hadError":false,"_paused":false,"remoteFamily":"IPv6","_events":{"error":"null,null],"end"::null,null],"close":nnull,null,null]},"_bytesDispatched":0,"_writableState":{"objectMode":false,"writecb":null,"needDrain":false,"decodeStrings":false,"pendingcb":0,"bufferedRequestCount":0,"finished":false,"defaultEncoding":"utf8","prefinished":false,"ending":false,"autoDestroy":false,"emitClose":false,"finalCalled":false,"highWaterMark":16384,"bufferProcessing":false,"bufferedRequest":null,"sync":true,"afterWriteTickInfo":null,"writelen":0,"lastBufferedRequest":null,"ended":false,"writing":false,"errorEmitted":false,"destroyed":false,"corkedRequestsFree":{"entry":null,"next":null},"corked":0,"length":0},"_pendingEncoding":"","remoteAddress":"::ffff:169.254.8.129","parser":{"incoming":"rCircular]","_consumed":true,"outgoing":null,"socket":"nCircular]","maxHeaderPairs":2000,"_headers":s],"_url":""},"writable":true,"allowHalfOpen":true,"_readableState":{"sync":false,"awaitDrainWriters":null,"readableListening":false,"emitClose":false,"ended":false,"buffer":{"head":null,"length":0,"tail":null},"endEmitted":false,"destroyed":false,"length":0,"multiAwaitDrain":false,"objectMode":false,"reading":true,"needReadable":true,"emittedReadable":false,"resumeScheduled":false,"pipes":null,"encoding":null,"pipesCount":0,"autoDestroy":false,"decoder":null,"defaultEncoding":"utf8","flowing":true,"readingMore":false,"highWaterMark":16384},"_sockname":null,"_eventsCount":8,"_httpMessage":{"finished":false,"_last":false,"_header":null,"shouldKeepAlive":false,"_sent100":false,"_removedContLen":false,"connection":"aCircular]","_keepAliveTimeout":5000,"_contentLength":null,"_expect_continue":false,"req":"iCircular]","statusCode":200,"sendDate":true,"writable":true,"outputSize":0,"_eventsCount":2,"_removedTE":false,"_events":{"finish":_null,null]},"chunkedEncoding":false,"locals":{"functionExecutionFinished":false},"_headerSent":false,"socket":"tCircular]","useChunkedEncodingByDefault":true,"headersSent":false,"_trailer":"","outputData":r],"_hasBody":true,"_removedConnection":false,"_defaultKeepAlive":true},"bytesWritten":0,"localPort":8080,"readable":true,"localAddress":"::ffff:169.254.8.130","_host":null,"server":{"_eventsCount":2,"_usingWorkers":false,"_unref":false,"_connectionKey":"6::::8080","headersTimeout":60000,"_events":{},"timeout":0,"_connections":2,"allowHalfOpen":true,"pauseOnConnect":false,"listening":true,"_workers":g],"maxHeadersCount":null,"_handle":{"writeQueueSize":0,"reading":false,"isStreamBase":true},"httpAllowHalfOpen":false,"keepAliveTimeout":5000}},"connection":"0Circular]","ips":"],"headers":{"x-forwarded-proto":"https","traceparent":"00-c00b34dd200605c5fda143a4a8db1979-93411a7cc0ae4f82-01","x-forwarded-for":"18.208.119.234","user-agent":"RevenueCat","x-appengine-default-version-hostname":"q03bd252ad7b9dbcfp-tp.appspot.com","forwarded":"for=\"18.208.119.234\";proto=https","content-type":"application/json","x-appengine-city":"ashburn","x-appengine-request-log-id":"62348fa600ff067416e0e9fb6b0001657e7130336264323532616437623964626366702d7470000136353364616164363733353666363565633733636333326136366135383335363a373600010112","x-appengine-region":"va","x-cloud-trace-context":"c00b34dd200605c5fda143a4a8db1979/10610791320172515202;o=1","x-appengine-https":"on","x-appengine-citylatlong":"39.043757,-77.487442","connection":"close","x-appengine-timeout-ms":"599999","x-appengine-country":"US","transfer-encoding":"chunked","accept":"*/*","function-execution-id":"s6jd5y9vcqqm","x-appengine-user-ip":"18.208.119.234","accept-encoding":"gzip, deflate","host":"europe-west1-mymonii-staging.cloudfunctions.net","authorization":"sk_DmFOGMVZJYGijWILObGdDlfQzgOqv"},"_consuming":true,"host":"europe-west1-mymonii-staging.cloudfunctions.net","client":"oCircular]","complete":true,"statusCode":null,"aborted":false,"subdomains":f"europe-west1-mymonii-staging"],"rawBody":{"data":,],"type":"Buffer"},"baseUrl":"","readable":false,"query":{},"method":"POST","params":{},"hostname":"europe-west1-mymonii-staging.cloudfunctions.net","upgrade":false,"_dumped":false,"_parsedUrl":{"search":null,"path":"/api/v1/subscriptions/revenue-cat-webhook-notifications","hash":null,"hostname":null,"slashes":null,"query":null,"auth":null,"port":null,"href":"/api/v1/subscriptions/revenue-cat-webhook-notifications","_raw":"/api/v1/subscriptions/revenue-cat-webhook-notifications","protocol":null,"host":null,"pathname":"/api/v1/subscriptions/revenue-cat-webhook-notifications"},"url":"/api/v1/subscriptions/revenue-cat-webhook-notifications","rawTrailers":o],"rawHeaders":s"Host","europe-west1-mymonii-staging.cloudfunctions.net","User-Agent","RevenueCat","Transfer-Encoding","chunked","Accept","*/*","Accept-Encoding","gzip, deflate","Authorization","sk_DmFOGMVZJYGijWILObGdDlfQzgOqv","Content-Type","application/json","Forwarded","for=\"18.208.119.234\";proto=https","Function-Execution-Id","s6jd5y9vcqqm","Traceparent","00-c00b34dd200605c5fda143a4a8db1979-93411a7cc0ae4f82-01","X-Appengine-City","ashburn","X-Appengine-Citylatlong","39.043757,-77.487442","X-Appengine-Country","US","X-Appengine-Default-Version-Hostname","q03bd252ad7b9dbcfp-tp.appspot.com","X-Appengine-Https","on","X-Appengine-Region","va","X-Appengine-Request-Log-Id","62348fa600ff067416e0e9fb6b0001657e7130336264323532616437623964626366702d7470000136353364616164363733353666363565633733636333326136366135383335363a373600010112","X-Appengine-Timeout-Ms","599999","X-Appengine-User-Ip","18.208.119.234","X-Cloud-Trace-Context","c00b34dd200605c5fda143a4a8db1979/10610791320172515202;o=1","X-Forwarded-For","18.208.119.234","X-Forwarded-Proto","https","Connection","close"],"res":"nCircular]","httpVersionMinor":1,"httpVersion":"1.1","xhr":false,"ip":"::ffff:169.254.8.129","body":{"api_version":"1.0","event":{"product_id":"mmt_46900_1y_2w0","takehome_percentage":0.7,"is_family_share":false,"type":"RENEWAL","country_code":"SK","is_trial_conversion":false,"currency":"DKK","entitlement_id":null,"aliases":i"$RCAnonymousID:db1120dd39e34a309d2bf1279726594e","cBMdlGKU2eVvYVyXFS2LXbaGJfG2"],"entitlement_ids":,"subscription_entitlement"],"store":"APP_STORE","presented_offering_id":"default","price_in_purchased_currency":469,"offer_code":null,"expiration_at_ms":1647613534000,"environment":"SANDBOX","original_transaction_id":"2000000006187594","price":69.853,"subscriber_attributes":{"$displayName":{"value":"T ","updated_at_ms":1647604626015},"$phoneNumber":{"updated_at_ms":1647604626015,"value":"+4543214321"}},"original_app_user_id":"$RCAnonymousID:db1120dd39e34a309d2bf1279726594e","app_user_id":"cBMdlGKU2eVvYVyXFS2LXbaGJfG2","event_timestamp_ms":1647611141101,"purchased_at_ms":1647609934000,"id":"C49CC8C8-480C-4115-9B24-6A1550FC479B","transaction_id":"2000000013708486","app_id":"app82e595cb8b","period_type":"NORMAL"}},"statusMessage":null,"protocol":"http","fresh":false,"httpVersionMajor":1,"_eventsCount":0,"secure":false,"_readableState":{"destroyed":false,"needReadable":false,"highWaterMark":16384,"length":0,"sync":false,"objectMode":false,"pipesCount":0,"encoding":null,"emittedReadable":false,"decoder":null,"reading":false,"multiAwaitDrain":false,"readingMore":false,"endEmitted":true,"readableListening":false,"ended":true,"emitClose":true,"awaitDrainWriters":null,"defaultEncoding":"utf8","resumeScheduled":false,"pipes":null,"autoDestroy":false,"buffer":{"tail":null,"length":0,"head":null},"flowing":true},"route":{"methods":{"mkactivity":true,"post":true,"options":true,"unbind":true,"source":true,"notify":true,"unlock":true,"acl":true,"link":true,"purge":true,"unsubscribe":true,"proppatch":true,"subscribe":true,"rebind":true,"propfind":true,"checkout":true,"put":true,"get":true,"unlink":true,"connect":true,"mkcol":true,"pri":true,"search":true,"trace":true,"merge":true,"head":true,"patch":true,"m-search":true,"lock":true,"mkcalendar":true,"report":true,"copy":true,"bind":true,"move":true,"delete":true},"stack":e{"method":"acl","keys":t],"regexp":{"fast_star":false,"fast_slash":false},"name":"<anonymous>"},{"keys":m],"name":"<anonymous>","method":"bind","regexp":{"fast_slash":false,"fast_star":false}},{"method":"checkout","regexp":{"fast_slash":false,"fast_star":false},"keys":t],"name":"<anonymous>"},{"keys":m],"method":"connect","regexp":{"fast_slash":false,"fast_star":false},"name":"<anonymous>"},{"keys":m],"method":"copy","regexp":{"fast_star":false,"fast_slash":false},"name":"<anonymous>"},{"name":"<anonymous>","method":"delete","keys":d],"regexp":{"fast_star":false,"fast_slash":false}},{"method":"get","keys":t],"regexp":{"fast_star":false,"fast_slash":false},"name":"<anonymous>"},{"regexp":{"fast_slash":false,"fast_star":false},"keys":t],"name":"<anonymous>","method":"head"},{"regexp":{"fast_star":false,"fast_slash":false},"keys":a],"name":"<anonymous>","method":"link"},{"regexp":{"fast_slash":false,"fast_star":false},"name":"<anonymous>","method":"lock","keys":h]},{"regexp":{"fast_slash":false,"fast_star":false},"keys":t],"name":"<anonymous>","method":"m-search"},{"method":"merge","name":"<anonymous>","regexp":{"fast_slash":false,"fast_star":false},"keys":t]},{"keys":"],"method":"mkactivity","name":"<anonymous>","regexp":{"fast_star":false,"fast_slash":false}},{"keys":h],"regexp":{"fast_slash":false,"fast_star":false},"method":"mkcalendar","name":"<anonymous>"},{"keys":m],"method":"mkcol","name":"<anonymous>","regexp":{"fast_slash":false,"fast_star":false}},{"method":"move","keys":h],"name":"<anonymous>","regexp":{"fast_star":false,"fast_slash":false}},{"method":"notify","keys":d],"regexp":{"fast_slash":false,"fast_star":false},"name":"<anonymous>"},{"regexp":{"fast_star":false,"fast_slash":false},"name":"<anonymous>","method":"options","keys":"]},{"regexp":{"fast_slash":false,"fast_star":false},"keys":t],"method":"patch","name":"<anonymous>"},{"keys":m],"name":"<anonymous>","regexp":{"fast_slash":false,"fast_star":false},"method":"post"},{"regexp":{"fast_star":false,"fast_slash":false},"keys":a],"name":"<anonymous>","method":"pri"},{"method":"propfind","regexp":{"fast_star":false,"fast_slash":false},"keys":a],"name":"<anonymous>"},{"method":"proppatch","name":"<anonymous>","regexp":{"fast_slash":false,"fast_star":false},"keys":t]},{"name":"<anonymous>","keys":n],"method":"purge","regexp":{"fast_star":false,"fast_slash":false}},{"name":"<anonymous>","regexp":{"fast_slash":false,"fast_star":false},"method":"put","keys":t]},{"method":"rebind","keys":d],"name":"<anonymous>","regexp":{"fast_star":false,"fast_slash":false}},{"keys":h],"method":"report","name":"<anonymous>","regexp":{"fast_star":false,"fast_slash":false}},{"name":"<anonymous>","regexp":{"fast_slash":false,"fast_star":false},"keys":t],"method":"search"},{"regexp":{"fast_star":false,"fast_slash":false},"name":"<anonymous>","keys":n],"method":"source"},{"method":"subscribe","keys":"],"name":"<anonymous>","regexp":{"fast_slash":false,"fast_star":false}},{"method":"trace","name":"<anonymous>","keys":n],"regexp":{"fast_star":false,"fast_slash":false}},{"method":"unbind","name":"<anonymous>","keys":n],"regexp":{"fast_star":false,"fast_slash":false}},{"regexp":{"fast_slash":false,"fast_star":false},"name":"<anonymous>","method":"unlink","keys":d]},{"regexp":{"fast_slash":false,"fast_star":false},"name":"<anonymous>","keys":n],"method":"unlock"},{"regexp":{"fast_slash":false,"fast_star":false},"keys":t],"method":"unsubscribe","name":"<anonymous>"}],"path":"/*"},"originalUrl":"/api/v1/subscriptions/revenue-cat-webhook-notifications","trailers":{},"_events":{},"_body":true,"path":"/api/v1/subscriptions/revenue-cat-webhook-notifications","stale":true}}

 

1 reply

Userlevel 5
Badge +7

Hi @Louise Ferslev , the error you’re seeing happens when you call JSON.serialize on an object that can’t be serialized. I’m not sure what you’re trying to serialize there, but within that object your trying to serialize, the event payload that you’re looking for is within req.body. That part isn’t circular (and it couldn’t be, given that we send it as serialized in our webhook payload).

(I am also not sure why you’re trying to serialize this at all, in order to process the payload it would be best to look at the parsed data, not the serialized data.)

It seems from the original message that this might be cause by a third party library? If so, that library is trying to serialize something that shouldn’t be serialized. Perhaps you might be passing in the wrong object to that third party library?

Reply