I have an eventing function that utilizes many cURL calls, each of which I have wrapped in a try/catch block. When an error occurs, I successfully catch the error, and then create a new document with a number of fields to retry the failed cURL call with some linear backoff.
My issue arises when I create the new retry document. I have a field named ‘error’ who’s value is set to the ‘err’ caught in the catch block. The purpose of this is to give my team some visibility into what types of failures we’re getting. The problem is the value is never correctly assigned, and retry_doc[‘error’] always equals {} (empty object). I’m confused because if I simply log the error after its caught, I see the error in the log file correctly. But, when I try to assign the error to the retry document field, its always an empty object.
Hi - can you please post the code? That might be easier to understand. Is retryDoc an array (i.e retryDoc[‘error’]) or an object (i.e. retryDoc.error )
Yeah, here’s an example of a try/catch, which then logs and passes the error to queueRetry(). I’ve verified the error gets passed to queueRetry() successfully by calling log() within queueRetry. The errorDoc gets created successfully, but as mentioned errorDoc.error is always {}.
Yeah using the bucket alias as a javascript object works, I first became familiar with that syntax from the couchbase documentation. And yes all the other fields are present. I tried both using couchbase.insert() and changing the name ‘error’ to ‘testError’ to no avail.
Oh interesting, what couchbase version are you using? We’re on enterprise 7.1.2. Also, not sure if this would matter, but the errors we’re seeing are typically 503s.
I’m getting “Need a cURL binding as the second parameter” because I’m passing the wrong args to the curl. But that’s not relevant to your issue of not being able to populated the ‘error’ property. (503 is service not available - of whatever you’re calling in curl, I guess).
Interesting. Well I’m not sure what to do. I’m glad it works on your end, but I’m still not having any luck. I can successfully log the error immediately within the catch block scope, but any other operations on the error fail. If I log ‘typeof error’ I get ‘object’, however iterating over the erroor (Object.keys().foreach()…) or trying to JSON.stringify(error) both just produce {}. Same result if I pass it as a parameter.
If the service being called is returning a 503, then your response will have a status of 503. i.e. If I make a curl that requires a password, I get back a response with a 401 status begin logged like this:
Then your handleMicoserviceApiResponse() is called, and if you end up in the catch(error) it’s because of an exception thrown by handleMicoserviceApiResponse()? An empty one, perhaps?
[ I had put dummy values in the curl arguments and curl was throwing an exception. After I changed the call to get a 401, there’s no exception thrown by curl, it must be coming from your handleMicoserviceApiResponse() ]