This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
/
Errors.java
47 lines (35 loc) · 1.53 KB
/
Errors.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.gettipsi.stripe;
import android.support.annotation.NonNull;
import com.facebook.react.bridge.ReadableMap;
import com.gettipsi.stripe.util.ArgCheck;
import java.util.HashMap;
import java.util.Map;
/**
* Created by ngoriachev on 30/07/2018.
*/
public final class Errors {
private static final Map<String, String> exceptionNameToErrorCode = new HashMap<>();
static {
exceptionNameToErrorCode.put("APIConnectionException", "apiConnection");
exceptionNameToErrorCode.put("StripeException", "stripe");
exceptionNameToErrorCode.put("CardException", "card");
exceptionNameToErrorCode.put("AuthenticationException", "authentication");
exceptionNameToErrorCode.put("PermissionException", "permission");
exceptionNameToErrorCode.put("InvalidRequestException", "invalidRequest");
exceptionNameToErrorCode.put("RateLimitException", "rateLimit");
exceptionNameToErrorCode.put("APIException", "api");
}
static String toErrorCode(@NonNull Exception exception) {
ArgCheck.nonNull(exception);
String simpleName = exception.getClass().getSimpleName();
String errorCode = exceptionNameToErrorCode.get(simpleName);
ArgCheck.nonNull(errorCode, simpleName);
return errorCode;
}
static String getErrorCode(@NonNull ReadableMap errorCodes, @NonNull String errorKey) {
return errorCodes.getMap(errorKey).getString("errorCode");
}
static String getDescription(@NonNull ReadableMap errorCodes, @NonNull String errorKey) {
return errorCodes.getMap(errorKey).getString("description");
}
}