question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTTPException always returns 200 [QUESTION]

See original GitHub issue

Maybe I am missing something as usual as i understand

 raise HTTPException(
            status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
            detail="File is not excel",
            headers={"X-Error": "There goes my error"},

        ) 

should return status code of 415, but I just always get 200, if line is changed to return Response(status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE, content="File is not excel",) voula I get a 415 response code, so I am a bit lost here. Maybe you can explain me, where is my mistake?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
galvakojiscommented, May 28, 2020

got it, you need to use exception_handler

so using this example is useless? image

0reactions
galvakojiscommented, Oct 18, 2022

Hello, well I think as 99% it happens to me me, it was user error, Maybe I forgot to import something or imported a wrong module On Tuesday, October 18, 2022 at 12:29:39 PM GMT+3, Saeed Esmaili @.***> wrote:

@galvakojis I didn’t get how you fixed this issue. I’m having the same issue, and couldn’t find anything about exception_handler in the docs. @app.get(“/ping”) async def pong(request: Request): return HTTPException(status_code=400, detail=“oops”) curl returns:

GET /ping HTTP/1.1 Host: localhost:8002 User-Agent: curl/7.79.1 accept: application/json

  • Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < date: Tue, 18 Oct 2022 09:25:19 GMT < server: uvicorn < content-length: 50 < content-type: application/json <
  • Connection #0 to host localhost left intact {“status_code”:400,“detail”:“oops”,“headers”:null}%

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

Read more comments on GitHub >

github_iconTop Results From Across the Web

StatusCode in IHttpModule is always 200? - Stack Overflow
I have an custom IHttpModule that handels all available events and logs the HttpContext.Current.Response.StatusCode to a file. My web.config ...
Read more >
Handling Exceptions Returned from the Web API
When you return an OK from your method, a 200 HTTP status code is returned, which signifies that no error has occurred.
Read more >
HTTP Status Codes: All 63 explained - including FAQ & Video
If all of your content returns a 200 OK status code you can rest assured that your website is working and is properly...
Read more >
Guide to Spring Boot REST API Error Handling - Toptal
If our service calls this method and returns directly to the controller, we'll get an HTTP code 200 (OK) even if the resource...
Read more >
How to make MVC action return a http error when validation ...
As I have been reading about this, ASP.Net MVC ignores the Status Code just specified (ex: 401) and always return 200. Can I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found