OpenFn / adaptors

The new home for OpenFn adaptors; re-usable connectors for the most common DPGs and DPI building blocks.
GNU General Public License v3.0
4 stars 8 forks source link

http: `errors` object is empty although api returns verbose response #624

Closed aleksa-krolls closed 12 hours ago

aleksa-krolls commented 3 weeks ago

Issue

I'm running this postPatient.js job against this sample payload using the latest version of the http adaptor.

post("Patient", {body: state.data,  
 headers: {'content-type': 'application/json'}, 
 parseAs: 'json',
 })

In app, in the Log I see a very verbose and helpful response. In my next workflow step, I would like to map some of these error details (e.g., resourceType, issue, meta) to a postgresql database to keep an external log of errors faced when migrating data to my fhir app.

Screenshot 2024-06-13 at 1 46 21 PM

However, in Output this response is not captured in the errors object, which is left blank.

Screenshot 2024-06-13 at 1 45 22 PM

Ideally errors should show me as much as possible from the API response!

See example run failure on app.openfn.org: https://app.openfn.org/projects/d52bd48e-451b-4a92-9aad-e7c62a7f0923/w/79930c19-1ce1-4144-82ab-e10d7652e2b5?a=b827f1ff-5723-45a1-aee8-9485afaffcac&m=expand&s=a3b64302-94f1-4cb5-9490-ba87eb6dd6c6#output

workaround

The below job using (errors: { 400: false } allows us to add API response from failed http request to our final state.

post("Patient", {body: state.data,  
 headers: {'content-type': 'application/json'}, 
 errors: { 400: false },    
 parseAs: 'json',
 }, state => {
  //console.log('response ::', JSON.stringify(state.response, null,2));
  state.data.response = state.response; 
  return state; 
 }
aleksa-krolls commented 3 weeks ago

hey @josephjclark - this is the http error issue we discussed today on slack. Assign back to me if you want Hunter/Mtuchi to work on this next week.

josephjclark commented 1 week ago

Hey somehow I only just saw this! This is actually a core issue, but I'll be fixing it in kit soon (I've crosslinked the issue)