2727# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2828# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2929# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+ from typing import Union
3031
31- from aiohttp .web import Request , Response
32+ from aiohttp .web import HTTPException , Request , Response
3233
3334from elasticapm .conf import Config
3435from elasticapm .utils import compat , get_url_dict
@@ -49,11 +50,11 @@ def get_data_from_request(request: Request, config: Config, event_type: str):
4950 return result
5051
5152
52- def get_data_from_response (response : Response , config : Config , event_type : str ):
53+ def get_data_from_response (response : Union [ HTTPException , Response ] , config : Config , event_type : str ):
5354 result = {}
54-
55- if isinstance (getattr ( response , " status" , None ) , compat .integer_types ):
56- result ["status_code" ] = response . status
55+ status = getattr ( response , "status" , getattr ( response , "status_code" , None ))
56+ if isinstance (status , compat .integer_types ):
57+ result ["status_code" ] = status
5758 if config .capture_headers and getattr (response , "headers" , None ):
5859 headers = response .headers
5960 result ["headers" ] = {key : ";" .join (headers .getall (key )) for key in compat .iterkeys (headers )}
0 commit comments