1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.kaiserpfalzedv.services.eansearch.mapper;
19
20 import org.springframework.stereotype.Service;
21
22 import feign.Response;
23 import feign.codec.ErrorDecoder;
24
25
26
27
28
29
30
31
32
33
34
35 @Service
36 public class ResponseErrorMapper implements ErrorDecoder {
37 public static final int INVALID_OPERATION = 400;
38 public static final int INVALID_ACCESS_TOKEN = 401;
39 public static final int REQUEST_LIMIT_REACHED = 402;
40 public static final int INVALID_HTTP_METHOD = 405;
41 public static final int RATE_LIMIT_REACHED = 429;
42
43 @Override
44 public EanSearchException decode(final String methodKey, final Response response) {
45 return switch (response.status()) {
46 case INVALID_OPERATION -> new EanSearchInvalidOperationException();
47 case INVALID_ACCESS_TOKEN -> new EanSearchInvalidAccessTokenException();
48 case REQUEST_LIMIT_REACHED -> new EanSearchRequestLimitReachedException();
49 case INVALID_HTTP_METHOD -> new EanSearchWrongHTTPMethodException();
50 case RATE_LIMIT_REACHED -> new EanSearchTooManyRequestsException();
51 default -> null;
52 };
53
54 }
55 }