File tree 2 files changed +32
-0
lines changed
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:
61
61
if self .body and isinstance (self .body , dict ) and "error" in self .body :
62
62
if isinstance (self .body ["error" ], dict ):
63
63
root_cause = self .body ["error" ]["root_cause" ][0 ]
64
+ caused_by = self .body ["error" ].get ("caused_by" , {})
64
65
cause = ", " .join (
65
66
filter (
66
67
None ,
67
68
[
68
69
repr (root_cause ["reason" ]),
69
70
root_cause .get ("resource.id" ),
70
71
root_cause .get ("resource.type" ),
72
+ caused_by .get ("reason" ),
71
73
],
72
74
)
73
75
)
Original file line number Diff line number Diff line change @@ -46,3 +46,33 @@ def test_transform_error_parse_with_error_string(self):
46
46
assert (
47
47
str (e ) == "ApiError(500, 'InternalServerError', 'something error message')"
48
48
)
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