-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DH-5444] Implement Error Codes on Engine (#408)
* [DH-5444] Implement Error Codes on Engine * Move error code logic into utils package
- Loading branch information
Showing
7 changed files
with
264 additions
and
290 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from fastapi.responses import JSONResponse | ||
|
||
ERROR_MAPPING = { | ||
"InvalidId": "invalid_object_id", | ||
"InvalidDBConnectionError": "invalid_database_connection", | ||
"InvalidURIFormatError": "invalid_database_uri_format", | ||
"SSHInvalidDatabaseConnectionError": "ssh_invalid_database_connection", | ||
"EmptyDBError": "empty_database", | ||
"DatabaseConnectionNotFoundError": "database_connection_not_found", | ||
"GoldenSQLNotFoundError": "golden_sql_not_found", | ||
"LLMNotSupportedError": "llm_model_not_supported", | ||
"PromptNotFoundError": "prompt_not_found", | ||
"SQLGenerationError": "sql_generation_not_created", | ||
"SQLInjectionError": "sql_injection", | ||
"SQLGenerationNotFoundError": "sql_generation_not_found", | ||
"NLGenerationError": "nl_generation_not_created", | ||
"MalformedGoldenSQLError": "invalid_golden_sql", | ||
} | ||
|
||
|
||
def error_response(error, detail: dict, default_error_code=""): | ||
return JSONResponse( | ||
status_code=400, | ||
content={ | ||
"error_code": ERROR_MAPPING.get( | ||
error.__class__.__name__, default_error_code | ||
), | ||
"message": str(error), | ||
"detail": detail, | ||
}, | ||
) |