最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Job Cancelled on Ktor's request executing - Stack Overflow

programmeradmin3浏览0评论

Basically, I've REST by Ktor in my android app. As remote data storage I'm using Back4App. When I send post method I have following message in ktor's logger:

REQUEST  failed with exception: java.util.concurrent.CancellationException: Job was cancelled

I don't manage coroutines logic in app, so I don't even understand why I keep getting this error.

By the way, when I use Insomnia to test method - everything is good. And when this error appears in app - app doesn't fall and keep ruuning.

So the question is: how to deal with that bug?

The code with request:

suspend fun addFeed(newFeedDto: FeedEntity): Result<Unit> = withContext(Dispatchers.IO) {
        runCatching {
            val response = client.post(BACK4APPURL) {
                contentType(ContentType.Application.Json)
                setBody(
                    FeedDto(
                        url1 = newFeedDto.url1,
                        url2 = newFeedDto.url2,
                        content = newFeedDto.content,
                        nytUrl = newFeedDto.nytUrl,
                        newsName = newFeedDto.newsName,
                        newsPreview = newFeedDto.newsPreviewUrl,
                        tags = newFeedDto.tags
                    )
                )
                headers {
                    append("X-Parse-Application-Id", **)
                    append("X-Parse-REST-API-Key",  **)
                }
            }

            if (response.status != HttpStatusCode.Created)
                error("Status ${response.status}")

            response.body()
        }
    }
发布评论

评论列表(0)

  1. 暂无评论