File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -61,13 +61,15 @@ def __str__(self) -> str:
6161 if self .body and isinstance (self .body , dict ) and "error" in self .body :
6262 if isinstance (self .body ["error" ], dict ):
6363 root_cause = self .body ["error" ]["root_cause" ][0 ]
64+ caused_by = self .body ["error" ].get ("caused_by" , {})
6465 cause = ", " .join (
6566 filter (
6667 None ,
6768 [
6869 repr (root_cause ["reason" ]),
6970 root_cause .get ("resource.id" ),
7071 root_cause .get ("resource.type" ),
72+ caused_by .get ("reason" ),
7173 ],
7274 )
7375 )
Original file line number Diff line number Diff line change @@ -46,3 +46,33 @@ def test_transform_error_parse_with_error_string(self):
4646 assert (
4747 str (e ) == "ApiError(500, 'InternalServerError', 'something error message')"
4848 )
49+
50+ def test_transform_invalid_media_type_error (self ):
51+ e = ApiError (
52+ message = "InvalidMediaType" ,
53+ meta = error_meta ,
54+ body = {
55+ "error" : {
56+ "root_cause" : [
57+ {
58+ "type" : "media_type_header_exception" ,
59+ "reason" : "Invalid media-type value on headers [Accept, Content-Type]" ,
60+ }
61+ ],
62+ "type" : "media_type_header_exception" ,
63+ "reason" : "Invalid media-type value on headers [Accept, Content-Type]" ,
64+ "caused_by" : {
65+ "type" : "status_exception" ,
66+ "reason" : "Accept version must be either version 8 or 7, but found 9. Accept=application/vnd.elasticsearch+json; compatible-with=9" ,
67+ },
68+ },
69+ "status" : 400 ,
70+ },
71+ )
72+
73+ assert str (e ) == (
74+ "ApiError(500, 'InvalidMediaType', "
75+ "'Invalid media-type value on headers [Accept, Content-Type]', "
76+ "Accept version must be either version 8 or 7, but found 9. "
77+ "Accept=application/vnd.elasticsearch+json; compatible-with=9)"
78+ )
You can’t perform that action at this time.
0 commit comments