Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add 410 and 429 error handling #366

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ description: FaunaDB JVM Driver Tests

executors:
core:
parameters:
version:
type: enum
enum: ["nightly"]
resource_class: large
docker:
- image: openjdk:11
- image: fauna/faunadb
- image: fauna/faunadb:latest
name: core

environment:
SBT_VERSION: 1.7.2
FAUNA_ROOT_KEY: secret
Expand Down Expand Up @@ -90,16 +85,15 @@ commands:
path: results/

jobs:
core-nightly:
core:
executor:
name: core
version: nightly
steps:
- build_and_test

workflows:
version: 2
build_and_test:
jobs:
- core-nightly:
- core:
context: faunadb-drivers
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
4.5.0
* Emit ResourceNotAvailableException when Fauna returns a 410 status code.
* Emit TooManyRequestsException when Fauna returns a 429 status code.

4.4.0
* Support for tags and traceparent headers. PR: https://github.com/fauna/faunadb-jvm/pull/362

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ This repository contains the FaunaDB drivers for the JVM languages. Currently, J

Javadocs and Scaladocs are hosted on GitHub:

* [faunadb-java](http://fauna.github.io/faunadb-jvm/4.4.0/faunadb-java/api/)
* [faunadb-scala](http://fauna.github.io/faunadb-jvm/4.4.0/faunadb-scala/api/)
* [faunadb-java](http://fauna.github.io/faunadb-jvm/4.5.0/faunadb-java/api/)
* [faunadb-scala](http://fauna.github.io/faunadb-jvm/4.5.0/faunadb-scala/api/)

Details Documentation for each language:

Expand Down Expand Up @@ -54,7 +54,7 @@ Download from the Maven central repository:
<dependency>
<groupId>com.faunadb</groupId>
<artifactId>faunadb-java</artifactId>
<version>4.4.0</version>
<version>4.5.0</version>
<scope>compile</scope>
</dependency>
...
Expand Down Expand Up @@ -207,7 +207,7 @@ List<Value> events = capturedEvents.get();
##### faunadb-scala/sbt

```scala
libraryDependencies += ("com.faunadb" %% "faunadb-scala" % "4.4.0")
libraryDependencies += ("com.faunadb" %% "faunadb-scala" % "4.5.0")
```

##### Basic Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ private void handleQueryErrors(int statusCode, String body) {
throw new NotFoundException(errorResponse);
case 409:
throw new TransactionContentionException(errorResponse);
case 410:
throw new ResourceNotAvailableException(errorResponse);
case 429:
throw new TooManyRequestsException(errorResponse);
case 500:
throw new InternalException(errorResponse);
case 503:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.faunadb.client.errors;

import com.faunadb.client.HttpResponses;

public class ResourceNotAvailableException extends FaunaException {
public ResourceNotAvailableException(HttpResponses.QueryErrorResponse response) {
super(response);
}
public ResourceNotAvailableException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.faunadb.client.errors;

import com.faunadb.client.HttpResponses;

public class TooManyRequestsException extends FaunaException {
public TooManyRequestsException(HttpResponses.QueryErrorResponse response) {
super(response);
}
public TooManyRequestsException(String message) {
super(message);
}
}
2 changes: 2 additions & 0 deletions faunadb-scala/src/main/scala/faunadb/FaunaClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ class FaunaClient private (connection: Connection) {
case 403 => parseErrorsAndFailWith(new PermissionDeniedException(_))
case 404 => parseErrorsAndFailWith(new NotFoundException(_))
case 409 => parseErrorsAndFailWith(new TransactionContentionException(_))
case 410 => parseErrorsAndFailWith(new ResourceNotAvailableException(_))
case 429 => parseErrorsAndFailWith(new TooManyRequestsException(_))
case 500 => parseErrorsAndFailWith(new InternalException(_))
case 503 => parseErrorsAndFailWith(new UnavailableException(_))
case _ => parseErrorsAndFailWith(new UnknownException(_))
Expand Down
17 changes: 17 additions & 0 deletions faunadb-scala/src/main/scala/faunadb/errors/FaunaException.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ case class NotFoundException(response: Option[QueryErrorResponse], message: Stri
def this(response: QueryErrorResponse) = this(Some(response), FaunaException.respToError(response.errors))
}

/**
* An exception thrown if FaunaDB responds with an HTTP 429, meaning the request was throttled.
*/
case class TooManyRequestsException(response: Option[QueryErrorResponse], message: String) extends FaunaException(response, message) {
def this(message: String) = this(None, message)
def this(response: QueryErrorResponse) = this(Some(response), FaunaException.respToError(response.errors))
}

/**
* Exception thrown if FaunaDB responds with an HTTP 410.
* One example of this is if an account is disabled.
*/
case class ResourceNotAvailableException(response: Option[QueryErrorResponse], message: String) extends FaunaException(response, message) {
def this(message: String) = this(None, message)
def this(response: QueryErrorResponse) = this(Some(response), FaunaException.respToError(response.errors))
}

/**
* An exception thrown if FaunaDB responds with an HTTP 500. Such errors represent an internal
* failure within the database.
Expand Down
2 changes: 1 addition & 1 deletion project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scoverage.ScoverageSbtPlugin.autoImport._

object Settings {

lazy val driverVersion = "4.4.0"
lazy val driverVersion = "4.5.0"

lazy val scala211 = "2.11.12"
lazy val scala212 = "2.12.14"
Expand Down