File tree Expand file tree Collapse file tree 7 files changed +84
-1
lines changed
sentry-kotlin-multiplatform/src
commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions
commonMain/kotlin/io/sentry/kotlin/multiplatform
commonMain/kotlin/sample.kmp.app
iosMain/kotlin/sample.kmp.app Expand file tree Collapse file tree 7 files changed +84
-1
lines changed Original file line number Diff line number Diff line change 4
4
5
5
### Features
6
6
7
- - Improve Objc/Swift experience with @HiddenFromObjc ([ #62 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/62 ) )
7
+ - feat: configuring http client errors for Apple targets ([ #76 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/76 ) )
8
+ - feat: improve Objc/Swift experience with @HiddenFromObjc ([ #62 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/62 ) )
8
9
- feat: add view hierarchy ([ #53 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/53 ) )
9
10
10
11
### Fixes
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package io.sentry.kotlin.multiplatform.extensions
2
2
3
3
import PrivateSentrySDKOnly.Sentry.PrivateSentrySDKOnly
4
4
import cocoapods.Sentry.SentryEvent
5
+ import cocoapods.Sentry.SentryHttpStatusCodeRange
5
6
import io.sentry.kotlin.multiplatform.BuildKonfig
6
7
import io.sentry.kotlin.multiplatform.CocoaSentryOptions
7
8
import io.sentry.kotlin.multiplatform.SentryOptions
@@ -59,4 +60,13 @@ internal fun CocoaSentryOptions.applyCocoaBaseOptions(options: SentryOptions) {
59
60
cocoaBreadcrumb?.toKmpBreadcrumb()
60
61
?.let { options.beforeBreadcrumb?.invoke(it) }?.toCocoaBreadcrumb()
61
62
}
63
+
64
+ enableCaptureFailedRequests = options.enableCaptureFailedRequests
65
+ failedRequestTargets = options.failedRequestTargets
66
+ failedRequestStatusCodes = options.failedRequestStatusCodes.map {
67
+ SentryHttpStatusCodeRange (
68
+ min = it.min.convert(),
69
+ max = it.max.convert()
70
+ )
71
+ }
62
72
}
Original file line number Diff line number Diff line change
1
+ package io.sentry.kotlin.multiplatform
2
+
3
+ /* *
4
+ * The Http status code range. Example for a range: 400 to 499, 500 to 599, 400 to 599 The range is
5
+ * inclusive so the min and max is considered part of the range.
6
+ *
7
+ * Example for a single status code 400, 500
8
+ */
9
+ public data class HttpStatusCodeRange (val min : Int = DEFAULT_MIN , val max : Int = DEFAULT_MAX ) {
10
+
11
+ public constructor (statusCode: Int ) : this (statusCode, statusCode)
12
+
13
+ public fun isInRange (statusCode : Int ): Boolean {
14
+ return statusCode in min.. max
15
+ }
16
+
17
+ public companion object {
18
+ public const val DEFAULT_MIN : Int = 500
19
+ public const val DEFAULT_MAX : Int = 599
20
+ }
21
+ }
Original file line number Diff line number Diff line change @@ -72,4 +72,28 @@ public open class SentryOptions {
72
72
* This is only available on iOS and Android.
73
73
*/
74
74
public var attachViewHierarchy: Boolean = false
75
+
76
+ /* *
77
+ * Enables or disables the feature to automatically capture HTTP client errors.
78
+ * This is enabled by default.
79
+ *
80
+ * Available on Apple.
81
+ */
82
+ public var enableCaptureFailedRequests: Boolean = true
83
+
84
+ /* *
85
+ * A list of HTTP status code ranges indicating which client errors should be captured as errors.
86
+ * By default, only HTTP client errors with a response code between 500 and 599 are captured as errors.
87
+ *
88
+ * Available on Apple.
89
+ */
90
+ public var failedRequestStatusCodes: List <HttpStatusCodeRange > = listOf (HttpStatusCodeRange ())
91
+
92
+ /* *
93
+ * A list of HTTP request targets indicating which client errors should be captured as errors with either regex or a plain string.
94
+ * By default, HTTP client errors from every target (.* regular expression) are automatically captured.
95
+ *
96
+ * Available on Apple.
97
+ */
98
+ public var failedRequestTargets: List <String > = listOf (" .*" )
75
99
}
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ struct ContentView: View {
11
11
Button ( " Capture Exception " ) {
12
12
LoginImpl ( ) . login ( username: " MyUsername " )
13
13
}
14
+ Button ( " Capture Http Client Error " ) {
15
+ HttpClientKt . captureHttpClientError ( )
16
+ }
14
17
Button ( " Hard Crash " ) {
15
18
LoginImpl ( ) . login ( username: nil )
16
19
}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package sample.kmp.app
2
2
3
3
import io.sentry.kotlin.multiplatform.Attachment
4
4
import io.sentry.kotlin.multiplatform.Context
5
+ import io.sentry.kotlin.multiplatform.HttpStatusCodeRange
5
6
import io.sentry.kotlin.multiplatform.OptionsConfiguration
6
7
import io.sentry.kotlin.multiplatform.Sentry
7
8
@@ -45,6 +46,8 @@ private fun optionsConfiguration(): OptionsConfiguration {
45
46
it.attachScreenshot = true
46
47
it.attachViewHierarchy = true
47
48
49
+ it.failedRequestStatusCodes = listOf (HttpStatusCodeRange (400 , 599 ))
50
+ it.failedRequestTargets = listOf (" httpbin.org" )
48
51
it.beforeBreadcrumb = { breadcrumb ->
49
52
breadcrumb.message = " Add message before every breadcrumb"
50
53
breadcrumb
Original file line number Diff line number Diff line change
1
+ package sample.kmp.app
2
+
3
+ import platform.Foundation.NSURL
4
+ import platform.Foundation.NSURLRequest
5
+ import platform.Foundation.NSURLSession
6
+ import platform.Foundation.dataTaskWithRequest
7
+
8
+ @Suppress(" Unused" ) // Called from Swift
9
+ fun captureHttpClientError () {
10
+ val url = NSURL (string = " https://httpbin.org/status/404" )
11
+ val request = NSURLRequest (uRL = url)
12
+ NSURLSession .sharedSession.dataTaskWithRequest(request) { data, response, error ->
13
+ if (error != null ) {
14
+ // handle error
15
+ println (" error: $error " )
16
+ } else {
17
+ // handle successful response
18
+ println (" response: $response " )
19
+ }
20
+ }.resume()
21
+ }
You can’t perform that action at this time.
0 commit comments