Skip to content

Commit 5f34bde

Browse files
committed
API stuffs complete
1 parent 7ce9028 commit 5f34bde

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/main/java/com/lightningkite/kotlin/networking/OkHttpExtensions.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fun String.toRequestBody(): RequestBody = object : RequestBody() {
6767

6868
fun File.toRequestBody(type: MediaType): RequestBody = object : RequestBody() {
6969
override fun contentLength(): Long = this@toRequestBody.length()
70-
override fun contentType(): MediaType = MediaTypes.TEXT
70+
override fun contentType(): MediaType = type
7171
override fun writeTo(sink: BufferedSink) {
7272
var source: Source? = null
7373
try {

src/main/java/com/lightningkite/kotlin/networking/TypedResponse.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ class TypedResponse<T>(
3030

3131
fun copy(code: Int, errorString: String?): TypedResponse<T> = TypedResponse<T>(code, result, headers, errorString?.toByteArray(), exception)
3232
fun <A> copy(result: A? = null): TypedResponse<A> = TypedResponse<A>(code, result, headers, errorBytes, exception)
33-
inline fun <A> map(mapper: (T) -> A): TypedResponse<A> = TypedResponse<A>(code, if (result != null) mapper(result) else null, headers, errorBytes, exception)
33+
inline fun <A> map(mapper: (T) -> A): TypedResponse<A> = try{
34+
TypedResponse<A>(code, if (result != null) mapper(result) else null, headers, errorBytes, exception)
35+
} catch(e:Exception){
36+
TypedResponse<A>(0, null, headers, errorBytes, e)
37+
}
3438
}
3539

3640
inline fun <T> (() -> TypedResponse<T>).captureSuccess(crossinline onSuccess: (T) -> Unit): () -> TypedResponse<T> {

0 commit comments

Comments
 (0)