Skip to content

Commit

Permalink
Workaround weird update task edge cases
Browse files Browse the repository at this point in the history
- if the project id provided in the task is invalid, we receive a 500 error from server
- if the project id doesn't match the updated task's one, we receive a 200 success without data (can't be used to move a task to another project)
  • Loading branch information
opatry committed Jan 7, 2024
1 parent d977d90 commit 3b294e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion lib/src/main/java/net/opatry/ticktick/TickTickService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,25 @@ class HttpTickTickService(private val httpClient: HttpClient) : TickTickService
}

override suspend fun updateTask(taskId: String, request: TaskUpdateRequest): Task {
return httpClient.postOrThrow("open/v1/task/${taskId}", request)
require(taskId == request.id) { "Provided task id ($taskId) and update request id (${request.id}) doesn't match." }
// FIXME edge cases encountered
// if the project id provided in the task is invalid, we receive a 500 error from server
// if the project id doesn't match the updated task's one, we receive a 200 success without data (can't be used to move a task to another project)
// return httpClient.postOrThrow("open/v1/task/${taskId}", request)
val response = httpClient.post("open/v1/task/${taskId}") {
contentType(ContentType.Application.Json)
setBody(request)
}

if (response.status.isSuccess()) {
if (response.bodyAsText().isNotEmpty()) {
return response.body()
} else {
throw ClientRequestException(response, "Task not updated (invalid project id? ${request.projectId})")
}
} else {
throw ClientRequestException(response, response.bodyAsText())
}
}

override suspend fun completeTask(projectId: String, taskId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class TickTickServiceTaskTest {
runBlocking {
ticktickService.updateTask(
"6247ee29630c800f064fd145",
TaskUpdateRequest(projectId = "", id = "", content = "Bar")
TaskUpdateRequest(projectId = "6226ff9877acee87727f6bca", id = "6247ee29630c800f064fd145", content = "Bar")
)
}
}
Expand Down

0 comments on commit 3b294e7

Please sign in to comment.