Giter VIP home page Giter VIP logo

Comments (5)

okigan avatar okigan commented on June 10, 2024

Thanks for looking into it.

If I recall, the intent was that raise_for_status() would raise an exception which would cause a different return code

I've made this repo to show the intent, check out and run venv and test targets.

Is this working as intended?

from awscurl.

stephenmuss avatar stephenmuss commented on June 10, 2024

Thanks for your quick response @okigan. I understand the intention, the main issue with raise_for_status() is that it raises an exception and will print also print a traceback.

As an example, using awscurl to call a lambda function url with something like the following:

awscurl -H 'Content-Type: application/json' -X POST -d '{"foo": "bar"}' --service lambda --region us-east-1 https://foo.lambda-url.us-east-1.on.aws/

I may expect to get a non-200 status code if the payload is incorrect. Currently with raise_for_status() this looks like

{"errors": {"msg": "Some detailed error description"}}
Traceback (most recent call last):
  File "/Users/steve/.local/share/virtualenvs/example/bin/awscurl", line 8, in <module>
    sys.exit(main())
  File "/Users/steve/.local/share/virtualenvs/example/lib/python3.10/site-packages/awscurl/awscurl.py", line 521, in main
    inner_main(sys.argv[1:])
  File "/Users/steve/.local/share/virtualenvs/example/lib/python3.10/site-packages/awscurl/awscurl.py", line 515, in inner_main
    response.raise_for_status()
  File "/Users/steve/.local/share/virtualenvs/example/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: https://foo.lambda-url.us-east-1.on.aws/

Whereas this would be more desirable

{"errors": {"msg": "Some detailed error description"}}

If the main intention was to raise a non-zero exit code could I suggest this instead?

    print(response.text)

    exit_code = 0 if response.ok else 1

    return exit_code

from awscurl.

stephenmuss avatar stephenmuss commented on June 10, 2024

I'm happy to open a PR if you are amenable to that.

from awscurl.

okigan avatar okigan commented on June 10, 2024

Yes, PR would be great!

I had a quick look at response.ok and looks like it also calls raise_for_status which would still produce the output you'd like to avoid? Something similar to this could get the behavior you are looking for.

Again, thanks for looking into this.

from awscurl.

stephenmuss avatar stephenmuss commented on June 10, 2024

Thanks @okigan. I have opened a PR in #153 with an explanation of why response.ok is still sufficient. Thanks for being open to the PR and even more thanks for the very handy tool you've written.

from awscurl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.