Skip to content

Commit

Permalink
Merge branch 'v2.0.0-beta' into TW-2441-bug-on-java-kotlin-when-using…
Browse files Browse the repository at this point in the history
…-limit-to-read-messages
  • Loading branch information
mrashed-dev authored Dec 14, 2023
2 parents 03af939 + 063f385 commit c097444
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [2.0.0-beta.3] - TBD
* Fixed int type being serialized to double sometimes
* Fixed `Auth.exchangeCodeForToken` always returning 401

## [2.0.0-beta.2] - Released 2023-11-21

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/com/nylas/models/NylasOAuthError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/main/kotlin/com/nylas/util/JsonHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -225,7 +225,7 @@ class JsonHelper {
*/
@JvmStatic
fun jsonRequestBody(json: String): RequestBody {
return RequestBody.create(jsonType(), json)
return RequestBody.create(jsonType(), json.toByteArray())
}
}
}

0 comments on commit c097444

Please sign in to comment.