Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standardize error structure in json responses. (#4170)
* Standardize error structure in json responses. Use named types for raising exceptions instead of http status codes peppered throughout the code. * Whitespace fix * Rename fix * Consistent naming for things related to KnownException, for traceability. * For input field validation errors, list the affected fields as separate json objects. Also uses cleaner helpers for exception mappers. * Whitespace * Rename to clarify exception class hierarchy * Wrap not found responses in a schema and adjusted mapper to match * Include issue id in comments.
- Loading branch information
1 parent
400d730
commit b3c6505
Showing
21 changed files
with
773 additions
and
359 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
airbyte-server/src/main/java/io/airbyte/server/errors/BadObjectSchemaKnownException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.server.errors; | ||
|
||
public class BadObjectSchemaKnownException extends KnownException { | ||
|
||
public BadObjectSchemaKnownException(String message) { | ||
super(message); | ||
} | ||
|
||
public BadObjectSchemaKnownException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
@Override | ||
public int getHttpCode() { | ||
return 422; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
airbyte-server/src/main/java/io/airbyte/server/errors/ConnectFailureKnownException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.server.errors; | ||
|
||
public class ConnectFailureKnownException extends KnownException { | ||
|
||
public ConnectFailureKnownException(String message) { | ||
super(message); | ||
} | ||
|
||
public ConnectFailureKnownException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
@Override | ||
public int getHttpCode() { | ||
return 400; | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
airbyte-server/src/main/java/io/airbyte/server/errors/IdNotFoundKnownException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.server.errors; | ||
|
||
import io.airbyte.api.model.NotFoundKnownExceptionInfo; | ||
import org.apache.logging.log4j.core.util.Throwables; | ||
|
||
public class IdNotFoundKnownException extends KnownException { | ||
|
||
String id; | ||
|
||
public IdNotFoundKnownException(String message, String id) { | ||
super(message); | ||
this.id = id; | ||
} | ||
|
||
public IdNotFoundKnownException(String message, String id, Throwable cause) { | ||
super(message, cause); | ||
this.id = id; | ||
} | ||
|
||
public IdNotFoundKnownException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
@Override | ||
public int getHttpCode() { | ||
return 404; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public NotFoundKnownExceptionInfo getNotFoundKnownExceptionInfo() { | ||
NotFoundKnownExceptionInfo exceptionInfo = new NotFoundKnownExceptionInfo() | ||
.exceptionClassName(this.getClass().getName()) | ||
.message(this.getMessage()) | ||
.exceptionStack(Throwables.toStringList(this)); | ||
if (this.getCause() != null) { | ||
exceptionInfo.rootCauseExceptionClassName(this.getClass().getClass().getName()); | ||
exceptionInfo.rootCauseExceptionStack(Throwables.toStringList(this.getCause())); | ||
} | ||
exceptionInfo.id(this.getId()); | ||
return exceptionInfo; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
airbyte-server/src/main/java/io/airbyte/server/errors/InternalServerKnownException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.server.errors; | ||
|
||
public class InternalServerKnownException extends KnownException { | ||
|
||
public InternalServerKnownException(String message) { | ||
super(message); | ||
} | ||
|
||
public InternalServerKnownException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
@Override | ||
public int getHttpCode() { | ||
return 500; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.