Currently i am working on a sample project using pydantic and starlette. This is code from main file:
async def submit(request):
response = await request.json()
resume = Resume(**response)
JsonResponse({"Hello":"World"})
Code from Validation file:
class Basics(BaseModel):
name: str
label: str
image: str
email: str
phone: str
url: str
summary: str
location: Location
profiles: List[Profiles]
@validator('email')
def email_validation(cls, v):
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
if (re.fullmatch(regex, v)):
return True
else:
raise ValueError("Email not valid")
Class Basics is a child class of class Resume. When the regex doesnt match it correctly raises a value error and internal server error is displayed in postman. But how do I return this error or some statement to postman other and prevent internal server error?