From 0a261af380e59011f4097c5bc926fd4ef34523b2 Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Sat, 7 Mar 2026 09:57:58 +0800 Subject: [PATCH] Clarify expired attachment errors in app --- .../kotlin/cn/xiaobai/openclawapp/App.kt | 30 ++++++++++++------- .../openclawapp/network/MobileGatewayApi.kt | 16 ++++++++-- docs/MVP_PROGRESS.md | 1 + 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt index 58afe76..efa65aa 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt @@ -224,21 +224,31 @@ private fun OpenClawRoot(appState: OpenClawAppState) { }, onOpenAttachment = { messageId -> coroutineScope.launch { - val payload = appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId) - if (payload != null) { - openAttachment(payload) - } else { - appState.feedbackMessage = "当前附件暂无可打开内容" + runCatching { + appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId) + }.onSuccess { payload -> + if (payload != null) { + openAttachment(payload) + } else { + appState.feedbackMessage = "当前附件暂无可打开内容" + } + }.onFailure { + appState.feedbackMessage = it.message ?: "打开附件失败" } } }, onDownloadAttachment = { messageId -> coroutineScope.launch { - val payload = appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId) - if (payload != null) { - saveAttachment(payload) - } else { - appState.feedbackMessage = "当前附件暂无可下载内容" + runCatching { + appState.repository.ensureAttachmentOpenPayload(activeSession.id, messageId) + }.onSuccess { payload -> + if (payload != null) { + saveAttachment(payload) + } else { + appState.feedbackMessage = "当前附件暂无可下载内容" + } + }.onFailure { + appState.feedbackMessage = it.message ?: "下载附件失败" } } }, diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayApi.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayApi.kt index 493561e..3a461ab 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayApi.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayApi.kt @@ -3,6 +3,7 @@ package cn.xiaobai.openclawapp.network import io.ktor.client.HttpClient import io.ktor.client.call.body import io.ktor.client.plugins.contentnegotiation.ContentNegotiation +import io.ktor.client.plugins.ClientRequestException import io.ktor.client.request.get import io.ktor.client.request.header import io.ktor.client.request.post @@ -103,9 +104,18 @@ class MobileGatewayApi( suspend fun readAttachment(sessionId: String, attachmentId: String): AttachmentReadResponseDto { val encodedId = sessionId.encodeURLPathPart() val encodedAttachmentId = attachmentId.encodeURLPathPart() - return client.get("${baseUrl.trimEnd('/')}/api/sessions/$encodedId/attachments/$encodedAttachmentId") { - authHeader() - }.body() + return try { + client.get("${baseUrl.trimEnd('/')}/api/sessions/$encodedId/attachments/$encodedAttachmentId") { + authHeader() + }.body() + } catch (e: ClientRequestException) { + val message = when (e.response.status.value) { + 403 -> "该附件不属于当前会话" + 404 -> "附件不存在或已过期" + else -> "读取附件失败(HTTP ${e.response.status.value})" + } + throw IllegalStateException(message, e) + } } private fun io.ktor.client.request.HttpRequestBuilder.authHeader() { diff --git a/docs/MVP_PROGRESS.md b/docs/MVP_PROGRESS.md index 36fa463..8e0f476 100644 --- a/docs/MVP_PROGRESS.md +++ b/docs/MVP_PROGRESS.md @@ -196,6 +196,7 @@ Android/iOS App - [x] 点击附件打开(Android,优先本地缓存;无缓存时经 BFF 回源读取) - [x] BFF 附件 overlay 落盘,重启后仍可读取最近附件 - [x] 下载附件(Android,系统另存为) +- [x] 附件过期/越权读取在前端已有明确提示文案 - [ ] iOS / Web 剪贴板 - [ ] iOS / Web 附件打开