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 3 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
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