-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: vamsi-amazon <reddyvam@amazon.com>
- Loading branch information
Showing
39 changed files
with
173 additions
and
93 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
...ce/DataSourceUserAuthorizationHelper.java → ...th/DataSourceUserAuthorizationHelper.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
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
77 changes: 77 additions & 0 deletions
77
datasources/src/main/java/org/opensearch/sql/datasources/exceptions/ErrorMessage.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,77 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
|
||
package org.opensearch.sql.datasources.exceptions; | ||
|
||
import com.google.gson.JsonObject; | ||
import lombok.Getter; | ||
import org.opensearch.rest.RestStatus; | ||
|
||
/** | ||
* Error Message. | ||
*/ | ||
public class ErrorMessage { | ||
|
||
protected Throwable exception; | ||
|
||
private final int status; | ||
|
||
@Getter | ||
private final String type; | ||
|
||
@Getter | ||
private final String reason; | ||
|
||
@Getter | ||
private final String details; | ||
|
||
/** | ||
* Error Message Constructor. | ||
*/ | ||
public ErrorMessage(Throwable exception, int status) { | ||
this.exception = exception; | ||
this.status = status; | ||
|
||
this.type = fetchType(); | ||
this.reason = fetchReason(); | ||
this.details = fetchDetails(); | ||
} | ||
|
||
private String fetchType() { | ||
return exception.getClass().getSimpleName(); | ||
} | ||
|
||
protected String fetchReason() { | ||
return status == RestStatus.BAD_REQUEST.getStatus() | ||
? "Invalid Request" | ||
: "There was internal problem at backend"; | ||
} | ||
|
||
protected String fetchDetails() { | ||
// Some exception prints internal information (full class name) which is security concern | ||
return emptyStringIfNull(exception.getLocalizedMessage()); | ||
} | ||
|
||
private String emptyStringIfNull(String str) { | ||
return str != null ? str : ""; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
JsonObject jsonObject = new JsonObject(); | ||
jsonObject.addProperty("status", status); | ||
jsonObject.add("error", getErrorAsJson()); | ||
return jsonObject.getAsString(); | ||
} | ||
|
||
private JsonObject getErrorAsJson() { | ||
JsonObject errorJson = new JsonObject(); | ||
errorJson.addProperty("type", type); | ||
errorJson.addProperty("reason", reason); | ||
errorJson.addProperty("details", details); | ||
return errorJson; | ||
} | ||
} |
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
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
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
2 changes: 1 addition & 1 deletion
2
...sql/datasource/DataSourceLoaderCache.java → ...ources/service/DataSourceLoaderCache.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
2 changes: 1 addition & 1 deletion
2
...datasource/DataSourceLoaderCacheImpl.java → ...es/service/DataSourceLoaderCacheImpl.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
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
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.