Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add a helper to determine if an exception is from a 304 Not Modified response. #5

Merged
merged 1 commit into from
Feb 15, 2023

Conversation

darronschall
Copy link
Contributor

@darronschall darronschall commented Feb 15, 2023

In practice, Ktor will throw a RedirectResponseException on a 304 Not Modified server result. This small helper lets us avoid having to repeat ourselves with a cast and status check when we're trying to determine what happened in our exception handling:

try {
   val (response, responseHeaders) = exampleService.getCacheData(...)
} catch (e: ServiceException) {
  if (e.isNotModifiedException()) {
    // Ignore, local cache is not stale.
  }
}

NotModified is not one of the Twirp Error code enums, so we're on our own in coming up with a way to handle it. Adding it as an enum makes a little more sense, but this works without creating our own extension of the Twirp spec.

…` response.

In practice, Ktor will throw a `RedirectResponseException` on a `304 Not Modified` server result. This small helper lets us avoid having to repeat ourselves with a cast and status check when we're trying to determine what happened in our exception handling:

```kotlin
try {
   val (response, responseHeaders) = exampleService.getCacheData(...)
} catch (e: ServiceException) {
  if (e.isNotModifiedException()) {
    // Ignore, local cache is not stale.
  }
}
```
@darronschall darronschall changed the title Add a helper to determine if an exception is from a `304 Not Modified… Add a helper to determine if an exception is from a 304 Not Modified response. Feb 15, 2023
@darronschall darronschall merged commit 8b2764a into main Feb 15, 2023
@darronschall darronschall deleted the add-service-exception-helper-for-not-modified branch February 15, 2023 21:07
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants