From 36af80fe965f49a6e6872a82d732a9a58ae39af8 Mon Sep 17 00:00:00 2001 From: fauna-chase Date: Thu, 26 Oct 2023 14:17:43 -0400 Subject: [PATCH 1/3] add 410 and 429 error handling --- .../java/com/faunadb/client/FaunaClient.java | 4 ++++ .../errors/ResourceNotAvailableException.java | 12 ++++++++++++ .../client/errors/TooManyRequestsException.java | 12 ++++++++++++ .../src/main/scala/faunadb/FaunaClient.scala | 2 ++ .../scala/faunadb/errors/FaunaException.scala | 17 +++++++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 faunadb-java/src/main/java/com/faunadb/client/errors/ResourceNotAvailableException.java create mode 100644 faunadb-java/src/main/java/com/faunadb/client/errors/TooManyRequestsException.java diff --git a/faunadb-java/src/main/java/com/faunadb/client/FaunaClient.java b/faunadb-java/src/main/java/com/faunadb/client/FaunaClient.java index f11f51c1..78444228 100644 --- a/faunadb-java/src/main/java/com/faunadb/client/FaunaClient.java +++ b/faunadb-java/src/main/java/com/faunadb/client/FaunaClient.java @@ -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: diff --git a/faunadb-java/src/main/java/com/faunadb/client/errors/ResourceNotAvailableException.java b/faunadb-java/src/main/java/com/faunadb/client/errors/ResourceNotAvailableException.java new file mode 100644 index 00000000..b52e57f2 --- /dev/null +++ b/faunadb-java/src/main/java/com/faunadb/client/errors/ResourceNotAvailableException.java @@ -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); + } +} diff --git a/faunadb-java/src/main/java/com/faunadb/client/errors/TooManyRequestsException.java b/faunadb-java/src/main/java/com/faunadb/client/errors/TooManyRequestsException.java new file mode 100644 index 00000000..7b17de7c --- /dev/null +++ b/faunadb-java/src/main/java/com/faunadb/client/errors/TooManyRequestsException.java @@ -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); + } +} diff --git a/faunadb-scala/src/main/scala/faunadb/FaunaClient.scala b/faunadb-scala/src/main/scala/faunadb/FaunaClient.scala index f1498e99..9c0cc103 100644 --- a/faunadb-scala/src/main/scala/faunadb/FaunaClient.scala +++ b/faunadb-scala/src/main/scala/faunadb/FaunaClient.scala @@ -402,6 +402,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(_)) diff --git a/faunadb-scala/src/main/scala/faunadb/errors/FaunaException.scala b/faunadb-scala/src/main/scala/faunadb/errors/FaunaException.scala index 1e8d2ffe..94cc7073 100644 --- a/faunadb-scala/src/main/scala/faunadb/errors/FaunaException.scala +++ b/faunadb-scala/src/main/scala/faunadb/errors/FaunaException.scala @@ -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. From 31352037b0dfe9359c9d13796bd51424b18f1402 Mon Sep 17 00:00:00 2001 From: Cleve Stuart Date: Thu, 26 Oct 2023 11:34:11 -0700 Subject: [PATCH 2/3] Try to fix circle ci --- .circleci/config.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 823fff3a..d13b8857 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,18 +3,11 @@ description: FaunaDB JVM Driver Tests executors: core: - parameters: - version: - type: enum - enum: ["nightly"] resource_class: large docker: - image: openjdk:11 - - image: gcr.io/faunadb-cloud/faunadb/enterprise/<>:latest + - image: fauna/faunadb:latest name: core - auth: - username: _json_key - password: $GCR_KEY environment: SBT_VERSION: 1.4.7 FAUNA_ROOT_KEY: secret @@ -92,10 +85,9 @@ commands: path: results/ jobs: - core-nightly: + core: executor: name: core - version: nightly steps: - build_and_test @@ -103,5 +95,5 @@ workflows: version: 2 build_and_test: jobs: - - core-nightly: + - core: context: faunadb-drivers From e744975dd37c8636e432845c76f1b864c5fa9813 Mon Sep 17 00:00:00 2001 From: Cleve Stuart Date: Thu, 26 Oct 2023 11:55:15 -0700 Subject: [PATCH 3/3] Bump version --- CHANGELOG.txt | 4 ++++ README.md | 8 ++++---- project/Settings.scala | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 7c4ef02a..0018ce4c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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 diff --git a/README.md b/README.md index e4b71b8b..5483f1c8 100644 --- a/README.md +++ b/README.md @@ -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: @@ -54,7 +54,7 @@ Download from the Maven central repository: com.faunadb faunadb-java - 4.4.0 + 4.5.0 compile ... @@ -207,7 +207,7 @@ List 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 diff --git a/project/Settings.scala b/project/Settings.scala index a8577e02..11a949bf 100644 --- a/project/Settings.scala +++ b/project/Settings.scala @@ -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"