Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catching HTTP errors #3

Closed
StephanGeorg opened this issue Oct 22, 2024 · 12 comments
Closed

Catching HTTP errors #3

StephanGeorg opened this issue Oct 22, 2024 · 12 comments

Comments

@StephanGeorg
Copy link

Hi @lmangani. Hi @ahuarte47.

First of all, thank you for this extension. Yes, I know, this is in very early stage but I've been dreaming of a feature like this for a long time because it enables and improves a lot of workflows and pipelines.

I'm not sure if you're open to feedback yet, but catching errors like this would be great:

Invalid Error: HTTP POST error: 404 - Not Found

Cheers.

@lmangani
Copy link
Collaborator

Hey @StephanGeorg thanks for giving this an early try, we really appreciate it!

Could you document the change proposal? ie: example query, current Output, desired output (or error, etc)

@StephanGeorg
Copy link
Author

StephanGeorg commented Oct 22, 2024

I'm using a MACRO to do the requests

CREATE OR REPLACE MACRO call_endpoint(a) AS (
  SELECT
    http_post(
      'https://domain.lol/api/endpoint',
      headers => MAP {
        'accept': 'application/json',
      },
      params => a
    )
    AS data);

and then apply that to all rows of a table

SELECT call_endpoint(MAP { 
  'countryCode': country,
  'street': street,
  'houseNumber': house_number,
  'postCode': postcode,
  'locality': city
}) AS output_data
FROM '/path/to/input.csv';

For some rows, the endpoint returns HTTP status code 404 because the input does not match any result. Instead of throwing

Invalid Error: HTTP POST error: 404 - Not Found

for all results, it should catch errors where the request was unsuccessful and return results where it was successful. Or you wrap the result into an object that contains the HTTP status code and the payload.

@ahuarte47
Copy link
Collaborator

Hello everyone, I love your idea of ​​changing the type of function results (From LogicalType::VARCHAR to LogicalType::JSON()). They could contain all the information returned by the request and the payload

@ahuarte47
Copy link
Collaborator

ahuarte47 commented Oct 22, 2024

Maybe returning some attributes from the Response object:
{ "body": "...", "status": 200, "reason": "..." }
Instead of throwing an error if code is not 200.
What do you think?

@ahuarte47
Copy link
Collaborator

ahuarte47 commented Oct 22, 2024

I have created this PR. Functions return now response data instead directly the body.

@lmangani
Copy link
Collaborator

Thanks @ahuarte47 for taking care of this so elegantly! Fantastic PR 🎉

A new version of the HTTP Client extension has been submitted to the community extension repo
duckdb/community-extensions#162

@ahuarte47
Copy link
Collaborator

Thanks @lmangani I did not know if you agreed this change, super!!!!

@StephanGeorg
Copy link
Author

Great work from both of you. Thank you so much.

@ahuarte47
Copy link
Collaborator

My apologies @lmangani I added a typo. This is the fix: #5

@lmangani
Copy link
Collaborator

Merged, Updated and Submitted to the registry 👍

@lmangani
Copy link
Collaborator

Closing as completed by the great @ahuarte47 🎉
@StephanGeorg if you find any issues during testing please feel free to reopen and/or share any new ideas

@StephanGeorg
Copy link
Author

Tested and can confirm: works as expected 🥳

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

No branches or pull requests

3 participants