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

Standardize error structure in json responses. #4170

Merged
merged 9 commits into from Jun 22, 2021

Conversation

airbyte-jenny
Copy link
Contributor

Standardize error structure in json responses. Use named types for raising exceptions instead of http status codes peppered throughout the code.

What

Various exception mappers created varying json structs for returning exception info. Some provided message and details, while others only provided message. Message was sometimes the details and other times just a title. HTTP status codes were determined in many places in the code, causing code repetition. Resulting errors were unpredictable for the UI to parse and display. Lack of consistency also made it hard to add tracking details later like request id.

How

KnownException has been standardized as the abstract parent of custom exceptions for various scenarios, and returns an ExceptionInfo in the json api response. The API is updated to support this, so the UI can rely on it.

Code now throws more specific named exceptions instead of needing to know an http status code, and status code is determined by the concrete child exception. This also adds stack trace lines for exception detail, and, if present, root cause exception, so that the UI can optionally show these where appropriate.

Recommended reading order

  1. airbyte-api/src/main/openapi/config.yaml (end of file, data structure for ExceptionInfo)
  2. airbyte-server/src/main/java/io/airbyte/server/errors/KnownExceptionMapper.java
  3. airbyte-server/src/main/java/io/airbyte/server/errors/KnownException.java
  4. airbyte-server/src/main/java/io/airbyte/server/errors/ValueConflictException.java
  5. airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java

Closes #3666

…ising exceptions instead of http status codes peppered throughout the code.
@github-actions github-actions bot added area/api Related to the api area/platform issues related to the platform area/documentation Improvements or additions to documentation labels Jun 16, 2021
Copy link
Contributor

@cgardens cgardens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple suggestions. LMK if you'd like to go over any of them.

Looking good! Now we can tell consumers we provide a sane, consistent interface when returning 400s/500s

airbyte-api/src/main/openapi/config.yaml Show resolved Hide resolved
throw new KnownException(
HttpStatus.UNPROCESSABLE_ENTITY_422,
String.format("Could not find configuration for %s: %s.", e.getType().toString(), e.getConfigId()), e);
throw new IdNotFoundException(String.format("Could not find configuration for %s: %s.", e.getType().toString(), e.getConfigId()), e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seeing these various exceptions that extend KnownException next to each other, I'm wondering if there's any naming convention we should adopt so it's clearer what these exceptions are doing. Because they're now not obviously known exceptions its hard to get the queue that these will be handled beautifully in the API. e.g. add KnownException (or some abbreviation, or some other naming convention entirely).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree. They should all include KnownException in the name, so that the hierarchy is more obvious, and also so they show up as autocomplete suggestions during IDE searches.

Copy link
Contributor

@cgardens cgardens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. 2 last thoughts but once you look at them feel free to merge it!

@@ -2667,8 +2667,94 @@ components:
- failed
reason:
type: string
InvalidInputProperty:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bummer that we have to lose the inheritance. i think it would be worthwhile leaving a comment explaining what the "required" fields of all exceptions are. maybe also worth mentioning why we are duplicating attributes as opposed to using inheritance.


public NotFoundKnownExceptionInfo getNotFoundKnownExceptionInfo() {
NotFoundKnownExceptionInfo exceptionInfo = new NotFoundKnownExceptionInfo()
.exceptionClassName(this.getClass().getName())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think you should have to use this in front of any of these method calls. welcome to keep it if you think it is clearer.

Copy link
Contributor

@davinchia davinchia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comments. Looks great otherwise! Feel free to merge whenever!

@airbyte-jenny airbyte-jenny merged commit b3c6505 into master Jun 22, 2021
@airbyte-jenny airbyte-jenny deleted the airbyte-jenny/issue-3666 branch June 22, 2021 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api Related to the api area/documentation Improvements or additions to documentation area/platform issues related to the platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Standardize Error Message Schema in API
3 participants