|
1 | 1 | import { SPAN_STATUS_ERROR, SPAN_STATUS_OK, startInactiveSpan } from '@sentry/core'; |
| 2 | +import { describeUrl } from './describeUrl'; |
2 | 3 | import { SPAN_ORIGIN_AUTO_RESOURCE_EXPO_IMAGE } from './origin'; |
3 | 4 |
|
4 | 5 | /** |
@@ -105,17 +106,23 @@ function wrapPrefetch<T extends ExpoImage>(imageClass: T): void { |
105 | 106 | }, |
106 | 107 | }); |
107 | 108 |
|
108 | | - return originalPrefetch(urls, cachePolicyOrOptions) |
109 | | - .then(result => { |
110 | | - span?.setStatus({ code: SPAN_STATUS_OK }); |
111 | | - span?.end(); |
112 | | - return result; |
113 | | - }) |
114 | | - .catch((error: unknown) => { |
115 | | - span?.setStatus({ code: SPAN_STATUS_ERROR, message: String(error) }); |
116 | | - span?.end(); |
117 | | - throw error; |
118 | | - }); |
| 109 | + try { |
| 110 | + return originalPrefetch(urls, cachePolicyOrOptions) |
| 111 | + .then(result => { |
| 112 | + span?.setStatus({ code: SPAN_STATUS_OK }); |
| 113 | + span?.end(); |
| 114 | + return result; |
| 115 | + }) |
| 116 | + .catch((error: unknown) => { |
| 117 | + span?.setStatus({ code: SPAN_STATUS_ERROR, message: String(error) }); |
| 118 | + span?.end(); |
| 119 | + throw error; |
| 120 | + }); |
| 121 | + } catch (error) { |
| 122 | + span?.setStatus({ code: SPAN_STATUS_ERROR, message: String(error) }); |
| 123 | + span?.end(); |
| 124 | + throw error; |
| 125 | + } |
119 | 126 | }) as T['prefetch']; |
120 | 127 | } |
121 | 128 |
|
@@ -144,32 +151,26 @@ function wrapLoadAsync<T extends ExpoImage>(imageClass: T): void { |
144 | 151 | }, |
145 | 152 | }); |
146 | 153 |
|
147 | | - return originalLoadAsync(source, options) |
148 | | - .then(result => { |
149 | | - span?.setStatus({ code: SPAN_STATUS_OK }); |
150 | | - span?.end(); |
151 | | - return result; |
152 | | - }) |
153 | | - .catch((error: unknown) => { |
154 | | - span?.setStatus({ code: SPAN_STATUS_ERROR, message: String(error) }); |
155 | | - span?.end(); |
156 | | - throw error; |
157 | | - }); |
| 154 | + try { |
| 155 | + return originalLoadAsync(source, options) |
| 156 | + .then(result => { |
| 157 | + span?.setStatus({ code: SPAN_STATUS_OK }); |
| 158 | + span?.end(); |
| 159 | + return result; |
| 160 | + }) |
| 161 | + .catch((error: unknown) => { |
| 162 | + span?.setStatus({ code: SPAN_STATUS_ERROR, message: String(error) }); |
| 163 | + span?.end(); |
| 164 | + throw error; |
| 165 | + }); |
| 166 | + } catch (error) { |
| 167 | + span?.setStatus({ code: SPAN_STATUS_ERROR, message: String(error) }); |
| 168 | + span?.end(); |
| 169 | + throw error; |
| 170 | + } |
158 | 171 | }) as T['loadAsync']; |
159 | 172 | } |
160 | 173 |
|
161 | | -function describeUrl(url: string): string { |
162 | | - try { |
163 | | - // Remove query string and fragment |
164 | | - const withoutQuery = url.split('?')[0] || url; |
165 | | - const withoutFragment = withoutQuery.split('#')[0] || withoutQuery; |
166 | | - const filename = withoutFragment.split('/').pop(); |
167 | | - return filename || url; |
168 | | - } catch { |
169 | | - return url; |
170 | | - } |
171 | | -} |
172 | | - |
173 | 174 | function describeSource(source: ExpoImageSource | string | number): string { |
174 | 175 | if (typeof source === 'number') { |
175 | 176 | return `asset #${source}`; |
|
0 commit comments