diff --git a/CHANGELOG.md b/CHANGELOG.md index 846ed51e..0c84c1f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Nylas Java SDK Changelog +## [2.0.0-beta.3] - TBD +* Fixed `Auth.exchangeCodeForToken` always returning 401 + ## [2.0.0-beta.2] - Released 2023-11-21 ### Added diff --git a/src/main/kotlin/com/nylas/interceptors/ContentHeadersInterceptor.kt b/src/main/kotlin/com/nylas/interceptors/ContentHeadersInterceptor.kt index 573bb2fc..fc12ded8 100644 --- a/src/main/kotlin/com/nylas/interceptors/ContentHeadersInterceptor.kt +++ b/src/main/kotlin/com/nylas/interceptors/ContentHeadersInterceptor.kt @@ -15,15 +15,21 @@ class ContentHeadersInterceptor : Interceptor { val path = request.url().encodedPath() val contentHeader = request.header(NylasClient.HttpHeaders.CONTENT_TYPE.headerName) if (contentHeader == null && !isDownloadablePath(path)) { - val enhancedRequest = request - .newBuilder() - .header( + val enhancedRequest = request.newBuilder() + if (request.body() != null && request.body()!!.contentType() != null) { + enhancedRequest.header( + NylasClient.HttpHeaders.CONTENT_TYPE.headerName, + request.body()!!.contentType()!!.toString(), + ) + } else if (request.body() != null) { + enhancedRequest.header( NylasClient.HttpHeaders.CONTENT_TYPE.headerName, NylasClient.MediaType.APPLICATION_JSON.mediaType, ) - .header(NylasClient.HttpHeaders.ACCEPT.headerName, NylasClient.MediaType.APPLICATION_JSON.mediaType) - .build() - return chain.proceed(enhancedRequest) + } + + enhancedRequest.header(NylasClient.HttpHeaders.ACCEPT.headerName, NylasClient.MediaType.APPLICATION_JSON.mediaType) + return chain.proceed(enhancedRequest.build()) } return chain.proceed(request) } diff --git a/src/main/kotlin/com/nylas/models/NylasOAuthError.kt b/src/main/kotlin/com/nylas/models/NylasOAuthError.kt index fdcb9490..6e5dd330 100644 --- a/src/main/kotlin/com/nylas/models/NylasOAuthError.kt +++ b/src/main/kotlin/com/nylas/models/NylasOAuthError.kt @@ -26,8 +26,13 @@ data class NylasOAuthError( */ @Json(name = "error_code") var errorCode: String, + /** + * The HTTP status code of the error response. + */ + @Json(name = "request_id") + override var requestId: String? = null, /** * The HTTP status code of the error response. */ override var statusCode: Int? = null, -) : AbstractNylasApiError(error, statusCode) +) : AbstractNylasApiError(error, statusCode, requestId) diff --git a/src/main/kotlin/com/nylas/util/JsonHelper.kt b/src/main/kotlin/com/nylas/util/JsonHelper.kt index fc10060d..d2f9aadb 100644 --- a/src/main/kotlin/com/nylas/util/JsonHelper.kt +++ b/src/main/kotlin/com/nylas/util/JsonHelper.kt @@ -193,7 +193,7 @@ class JsonHelper { return json } - private val jsonType = MediaType.parse("application/json; charset=utf-8") + private val jsonType = MediaType.parse("application/json") /** * Get the JSON media type. @@ -225,7 +225,7 @@ class JsonHelper { */ @JvmStatic fun jsonRequestBody(json: String): RequestBody { - return RequestBody.create(jsonType(), json) + return RequestBody.create(jsonType(), json.toByteArray()) } } }