File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 11from  fastapi  import  FastAPI 
2+ from  fastapi .exceptions  import  RequestValidationError , ValidationError 
3+ 
4+ from  json  import  loads 
25
36from  starlette .middleware .cors  import  CORSMiddleware 
7+ from  starlette .responses  import  JSONResponse 
48
59from  app .router  import  api_router 
610
11+ from  app .utils .json_encoder  import  JSONEncoder 
12+ 
713
814description  =  'A simple backend for dependency extraction' 
915
2228    },
2329)
2430
31+ @app .exception_handler (RequestValidationError ) 
32+ @app .exception_handler (ValidationError ) 
33+ async  def  validation_exception_handler (_  , exc ):
34+     exc_json  =  loads (exc .json ())
35+     response  =  {'message' : []}
36+     for  error  in  exc_json :
37+         response ['message' ].append (error ['loc' ][- 1 ]+ f": { error ['msg' ]}  )
38+     
39+     return  JSONResponse (content  =  JSONEncoder ().encode (response ), status_code  =  422 )
40+ 
2541# Set all CORS enabled origins 
2642app .add_middleware (
2743    CORSMiddleware ,
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments