File tree Expand file tree Collapse file tree 2 files changed +14
-11
lines changed
main/java/com/palantir/deadlines
test/java/com/palantir/deadlines Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -41,14 +41,17 @@ public static <T> Optional<DeadlineExpiredException> parseFromResponse(
41
41
});
42
42
}
43
43
44
- public static int getHttpStatusCode (DeadlineExpiredException .External _exception ) {
45
- // external deadline expiration is considered a client error
46
- return 400 ;
47
- }
48
-
49
- public static int getHttpStatusCode (DeadlineExpiredException .Internal _exception ) {
50
- // internal deadline expiration is considered a server error
51
- return 500 ;
44
+ public static int getHttpStatusCode (DeadlineExpiredException exception ) {
45
+ if (exception instanceof DeadlineExpiredException .External ) {
46
+ // external deadline expiration is considered a client error
47
+ return 400 ;
48
+ } else if (exception instanceof DeadlineExpiredException .Internal ) {
49
+ // internal deadline expiration is considered a server error
50
+ return 500 ;
51
+ } else {
52
+ // anything else is considered a server error
53
+ return 500 ;
54
+ }
52
55
}
53
56
54
57
public interface ResponseEncodingAdapter <RESPONSE > {
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class DeadlineExpiredReasonsTest {
28
28
29
29
@ Test
30
30
public void encodes_external_to_response () {
31
- DeadlineExpiredException . External exception = DeadlineExpiredException .external ();
31
+ DeadlineExpiredException exception = DeadlineExpiredException .external ();
32
32
TestResponse response = new TestResponse ();
33
33
response .status = DeadlineExpiredReasons .getHttpStatusCode (exception );
34
34
DeadlineExpiredReasons .encodeToResponse (exception , response , Encoder .INSTANCE );
@@ -38,10 +38,10 @@ public void encodes_external_to_response() {
38
38
39
39
@ Test
40
40
public void encodes_internal_to_response () {
41
- DeadlineExpiredException . Internal exception = DeadlineExpiredException .internal ();
41
+ DeadlineExpiredException exception = DeadlineExpiredException .internal ();
42
42
TestResponse response = new TestResponse ();
43
43
response .status = DeadlineExpiredReasons .getHttpStatusCode (exception );
44
- DeadlineExpiredReasons .encodeToResponse (DeadlineExpiredException . internal () , response , Encoder .INSTANCE );
44
+ DeadlineExpiredReasons .encodeToResponse (exception , response , Encoder .INSTANCE );
45
45
assertThat (response .status ).isEqualTo (500 );
46
46
assertThat (response .headers ).contains (entry (DeadlinesHttpHeaders .DEADLINE_EXPIRED_REASON , "internal" ));
47
47
}
You can’t perform that action at this time.
0 commit comments