Ufoptg commited on
Commit
e4bdde1
1 Parent(s): 0d38561

Update main.py

Browse files

custom_exception_handler

Files changed (1) hide show
  1. main.py +14 -0
main.py CHANGED
@@ -876,3 +876,17 @@ def myfile(link: Union[str, None] = None):
876
  return jsondata
877
  except:
878
  return "{'status': 'false', 'message': 'Invalid Link'}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
876
  return jsondata
877
  except:
878
  return "{'status': 'false', 'message': 'Invalid Link'}"
879
+
880
+ def custom_exception_handler(request: Request, exc: HTTPException) -> JSONResponse:
881
+ error_detail = [{"error": str(exc.detail)}]
882
+ custom_error_model = CustomErrorResponseModel(detail=error_detail)
883
+
884
+ return JSONResponse(
885
+ status_code=exc.status_code,
886
+ content=custom_error_model.dict(),
887
+ headers=exc.headers,
888
+ background=exc.background,
889
+ )
890
+
891
+ # Add the custom exception handler to your FastAPI app
892
+ app.add_exception_handler(HTTPException, custom_exception_handler)