Skip to content

Commit

Permalink
Catch the exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Barashev committed Jan 24, 2022
1 parent c048f7e commit dd01697
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ganttproject-builder/logging.properties
Expand Up @@ -14,6 +14,8 @@ net.sourceforge.ganttproject.task.algorithm.SchedulerImpl.level = INFO
io.milton.httpclient.level = INFO

App.Update.level = INFO
Cloud.Document.level = INFO
Cloud.Document.History.level = INFO
Cloud.Http.level = INFO
Export.level = INFO
Export.Progress.level = INFO
Expand Down
Expand Up @@ -206,6 +206,7 @@ interface OnlineDocument {
val mode: ObjectProperty<OnlineDocumentMode>
val fetchResultProperty: ObservableObjectValue<FetchResult?>
val latestVersionProperty: ObservableObjectValue<LatestVersion>
val id: String

fun setMirrored(mirrored: Boolean)
suspend fun fetch(): FetchResult
Expand Down
Expand Up @@ -45,6 +45,7 @@ import net.sourceforge.ganttproject.gui.options.OptionPageProviderBase
import net.sourceforge.ganttproject.language.GanttLanguage
import java.awt.BorderLayout
import java.awt.Component
import java.io.IOException
import java.time.Duration
import java.util.*
import javax.swing.JPanel
Expand Down Expand Up @@ -202,9 +203,20 @@ class DocPropertiesUi(val errorUi: ErrorUi, val busyUi: BusyUi) {
btnGet.addEventHandler(ActionEvent.ACTION) {
val selected = listView.selectionModel.selectedItem?.resource?.get() ?: return@addEventHandler
ourCoroutines.launch {
folderView.document?.fetchVersion(selected.generation)?.also {
it.update()
fetchConsumer(it)
folderView.document?.let { doc ->
try {
doc.fetchVersion(selected.generation).also {
it.update()
fetchConsumer(it)
}
} catch (ex: IOException) {
ourLogger.error("Failed to fetch the document version from the history", mapOf(
"doc" to doc.id,
"user" to GPCloudOptions.userId.value,
"generation" to selected.generation
))
errorUi(ex.message ?: "")
}
}
}
}
Expand Down Expand Up @@ -461,3 +473,4 @@ private val OFFLINE_MIRROR_LOCALIZER = RootLocalizer.createWithRootKey(
"cloud.offlineMirrorOptionPane", BROWSE_PANE_LOCALIZER)
private val LOCK_LOCALIZER = RootLocalizer.createWithRootKey("cloud.lockOptionPane")
private val ourCoroutines = CoroutineScope(Dispatchers.JavaFx)
private val ourLogger = GPLogger.create("Cloud.Document.History")
Expand Up @@ -73,6 +73,8 @@ class GPCloudDocument(val teamRefid: String?,
override val mode = SimpleObjectProperty(OnlineDocumentMode.ONLINE_ONLY)
override val fetchResultProperty = SimpleObjectProperty<FetchResult>()
override val latestVersionProperty = SimpleObjectProperty<LatestVersion>(this, "")
override val id: String
get() = this.projectRefid ?: ""

private val queryArgs: String
get() = "?projectRefid=${this.projectRefid}"
Expand Down Expand Up @@ -300,11 +302,12 @@ class GPCloudDocument(val teamRefid: String?,
return callReadProject()
}

@Throws(ForbiddenException::class, PaymentRequiredException::class, ForbiddenException::class)
override suspend fun fetchVersion(version: Long): FetchResult {
return callReadProject(version)
}

@Throws(ForbiddenException::class)
@Throws(ForbiddenException::class, PaymentRequiredException::class, ForbiddenException::class)
private fun callReadProject(version: Long = -1): FetchResult {
LOG.debug("Calling /p/read")
val http = this.httpClientFactory()
Expand Down

0 comments on commit dd01697

Please sign in to comment.