aio-libs / aio-libs/aiohttp

Feature: make `HTTPException` non-abstract

Aperta
#4,034 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
Python
Stelle
16.5k
Fork
2.4k
Merge medio
20h 10m
PR unite (30g)
221

Descrizione

## Long story short
Use-case: a server's handler uses a client to make a request to another server. I would like to re-use the response status code in the first server's response (the code below does not work as `HTTPException`'s constructor does not accept parameter `status_code`):
```
try:
...
except ClientResponseError as e:
status = e.status or 500
raise web.HTTPException(text=e.message, status_code=status)
```

Of course I can use `return web.Response(text=e.message, status=status)`, but `web.Response` cannot be throwed, however I need it in my applicatoin.

## Expected behaviour

I would expect `web.HTTPException` not to be abstract so that one can construct and raise it with a dynamic status code.

## Actual behaviour
one cannot create an instance of `web.HTTPException`

## Steps to reproduce
(not a bug so no steps to reproduce)

## Your environment
(not a bug so no environment description)

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.