mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 03:29:01 +08:00
Refactor error handling in GenerateTaskPipeline class (#2345)
This commit is contained in:
parent
cd078a6264
commit
a58612718e
@ -463,44 +463,30 @@ class GenerateTaskPipeline:
|
|||||||
:param e: exception
|
:param e: exception
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if isinstance(e, ValueError):
|
error_responses = {
|
||||||
data = {
|
ValueError: {'code': 'invalid_param', 'status': 400},
|
||||||
'code': 'invalid_param',
|
ProviderTokenNotInitError: {'code': 'provider_not_initialize', 'status': 400},
|
||||||
'message': str(e),
|
QuotaExceededError: {
|
||||||
'status': 400
|
|
||||||
}
|
|
||||||
elif isinstance(e, ProviderTokenNotInitError):
|
|
||||||
data = {
|
|
||||||
'code': 'provider_not_initialize',
|
|
||||||
'message': e.description,
|
|
||||||
'status': 400
|
|
||||||
}
|
|
||||||
elif isinstance(e, QuotaExceededError):
|
|
||||||
data = {
|
|
||||||
'code': 'provider_quota_exceeded',
|
'code': 'provider_quota_exceeded',
|
||||||
'message': "Your quota for Dify Hosted Model Provider has been exhausted. "
|
'message': "Your quota for Dify Hosted Model Provider has been exhausted. "
|
||||||
"Please go to Settings -> Model Provider to complete your own provider credentials.",
|
"Please go to Settings -> Model Provider to complete your own provider credentials.",
|
||||||
'status': 400
|
'status': 400
|
||||||
}
|
},
|
||||||
elif isinstance(e, ModelCurrentlyNotSupportError):
|
ModelCurrentlyNotSupportError: {'code': 'model_currently_not_support', 'status': 400},
|
||||||
data = {
|
InvokeError: {'code': 'completion_request_error', 'status': 400}
|
||||||
'code': 'model_currently_not_support',
|
}
|
||||||
'message': e.description,
|
|
||||||
'status': 400
|
# Determine the response based on the type of exception
|
||||||
}
|
data = error_responses.get(type(e))
|
||||||
elif isinstance(e, InvokeError):
|
if data:
|
||||||
data = {
|
data.setdefault('message', getattr(e, 'description', str(e)))
|
||||||
'code': 'completion_request_error',
|
|
||||||
'message': e.description,
|
|
||||||
'status': 400
|
|
||||||
}
|
|
||||||
else:
|
else:
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
data = {
|
data = {
|
||||||
'code': 'internal_server_error',
|
'code': 'internal_server_error',
|
||||||
'message': 'Internal Server Error, please contact support.',
|
'message': 'Internal Server Error, please contact support.',
|
||||||
'status': 500
|
'status': 500
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'event': 'error',
|
'event': 'error',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user