|
1 | 1 | package io.sentry.react; |
2 | 2 |
|
3 | 3 | import com.facebook.react.bridge.ReadableMap; |
4 | | - |
5 | | -import org.jetbrains.annotations.NotNull; |
6 | | -import org.jetbrains.annotations.Nullable; |
7 | | - |
8 | | -import java.util.Map; |
9 | | - |
10 | 4 | import io.sentry.Breadcrumb; |
11 | 5 | import io.sentry.SentryLevel; |
| 6 | +import java.util.Map; |
| 7 | +import org.jetbrains.annotations.NotNull; |
| 8 | +import org.jetbrains.annotations.Nullable; |
12 | 9 |
|
13 | 10 | public class RNSentryBreadcrumb { |
14 | 11 |
|
15 | | - @Nullable |
16 | | - public static String getCurrentScreenFrom(ReadableMap from) { |
17 | | - final @Nullable String maybeCategory = from.hasKey("category") ? from.getString("category") : null; |
18 | | - if (maybeCategory == null || !maybeCategory.equals("navigation")) { |
19 | | - return null; |
20 | | - } |
21 | | - |
22 | | - final @Nullable ReadableMap maybeData = from.hasKey("data") ? from.getMap("data") : null; |
23 | | - if (maybeData == null) { |
24 | | - return null; |
25 | | - } |
| 12 | + @Nullable |
| 13 | + public static String getCurrentScreenFrom(ReadableMap from) { |
| 14 | + final @Nullable String maybeCategory = |
| 15 | + from.hasKey("category") ? from.getString("category") : null; |
| 16 | + if (maybeCategory == null || !maybeCategory.equals("navigation")) { |
| 17 | + return null; |
| 18 | + } |
26 | 19 |
|
27 | | - try { |
28 | | - // getString might throw if cast to string fails (data.to is not enforced by TS to be a string) |
29 | | - return maybeData.hasKey("to") ? maybeData.getString("to") : null; |
30 | | - } catch (Throwable exception) { |
31 | | - return null; |
32 | | - } |
| 20 | + final @Nullable ReadableMap maybeData = from.hasKey("data") ? from.getMap("data") : null; |
| 21 | + if (maybeData == null) { |
| 22 | + return null; |
33 | 23 | } |
34 | 24 |
|
35 | | - @NotNull |
36 | | - public static Breadcrumb fromMap(ReadableMap from) { |
37 | | - final @NotNull Breadcrumb breadcrumb = new Breadcrumb(); |
| 25 | + try { |
| 26 | + // getString might throw if cast to string fails (data.to is not enforced by TS to be a |
| 27 | + // string) |
| 28 | + return maybeData.hasKey("to") ? maybeData.getString("to") : null; |
| 29 | + } catch (Throwable exception) { |
| 30 | + return null; |
| 31 | + } |
| 32 | + } |
38 | 33 |
|
39 | | - if (from.hasKey("message")) { |
40 | | - breadcrumb.setMessage(from.getString("message")); |
41 | | - } |
| 34 | + @NotNull |
| 35 | + public static Breadcrumb fromMap(ReadableMap from) { |
| 36 | + final @NotNull Breadcrumb breadcrumb = new Breadcrumb(); |
42 | 37 |
|
43 | | - if (from.hasKey("type")) { |
44 | | - breadcrumb.setType(from.getString("type")); |
45 | | - } |
| 38 | + if (from.hasKey("message")) { |
| 39 | + breadcrumb.setMessage(from.getString("message")); |
| 40 | + } |
46 | 41 |
|
47 | | - if (from.hasKey("category")) { |
48 | | - breadcrumb.setCategory(from.getString("category")); |
49 | | - } |
| 42 | + if (from.hasKey("type")) { |
| 43 | + breadcrumb.setType(from.getString("type")); |
| 44 | + } |
50 | 45 |
|
51 | | - if (from.hasKey("level")) { |
52 | | - switch (from.getString("level")) { |
53 | | - case "fatal": |
54 | | - breadcrumb.setLevel(SentryLevel.FATAL); |
55 | | - break; |
56 | | - case "warning": |
57 | | - breadcrumb.setLevel(SentryLevel.WARNING); |
58 | | - break; |
59 | | - case "debug": |
60 | | - breadcrumb.setLevel(SentryLevel.DEBUG); |
61 | | - break; |
62 | | - case "error": |
63 | | - breadcrumb.setLevel(SentryLevel.ERROR); |
64 | | - break; |
65 | | - case "info": |
66 | | - default: |
67 | | - breadcrumb.setLevel(SentryLevel.INFO); |
68 | | - break; |
69 | | - } |
70 | | - } |
| 46 | + if (from.hasKey("category")) { |
| 47 | + breadcrumb.setCategory(from.getString("category")); |
| 48 | + } |
71 | 49 |
|
| 50 | + if (from.hasKey("level")) { |
| 51 | + switch (from.getString("level")) { |
| 52 | + case "fatal": |
| 53 | + breadcrumb.setLevel(SentryLevel.FATAL); |
| 54 | + break; |
| 55 | + case "warning": |
| 56 | + breadcrumb.setLevel(SentryLevel.WARNING); |
| 57 | + break; |
| 58 | + case "debug": |
| 59 | + breadcrumb.setLevel(SentryLevel.DEBUG); |
| 60 | + break; |
| 61 | + case "error": |
| 62 | + breadcrumb.setLevel(SentryLevel.ERROR); |
| 63 | + break; |
| 64 | + case "info": |
| 65 | + default: |
| 66 | + breadcrumb.setLevel(SentryLevel.INFO); |
| 67 | + break; |
| 68 | + } |
| 69 | + } |
72 | 70 |
|
73 | | - if (from.hasKey("data")) { |
74 | | - final ReadableMap data = from.getMap("data"); |
75 | | - for (final Map.Entry<String, Object> entry : data.toHashMap().entrySet()) { |
76 | | - final Object value = entry.getValue(); |
77 | | - // data is ConcurrentHashMap and can't have null values |
78 | | - if (value != null) { |
79 | | - breadcrumb.setData(entry.getKey(), entry.getValue()); |
80 | | - } |
81 | | - } |
| 71 | + if (from.hasKey("data")) { |
| 72 | + final ReadableMap data = from.getMap("data"); |
| 73 | + for (final Map.Entry<String, Object> entry : data.toHashMap().entrySet()) { |
| 74 | + final Object value = entry.getValue(); |
| 75 | + // data is ConcurrentHashMap and can't have null values |
| 76 | + if (value != null) { |
| 77 | + breadcrumb.setData(entry.getKey(), entry.getValue()); |
82 | 78 | } |
83 | | - |
84 | | - return breadcrumb; |
| 79 | + } |
85 | 80 | } |
86 | 81 |
|
| 82 | + return breadcrumb; |
| 83 | + } |
87 | 84 | } |
0 commit comments