diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bb8db3..6aec0a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This changelog documents the changes between release versions. ## [Unreleased] Changes to be included in the next upcoming release +## [0.0.38] - 2024-08-08 +* Add errors and error handling to SDK + ## [0.0.37] - 2024-08-07 * Fix schema endpoint to be aware of parallel execution diff --git a/connector-definition/template/functions.py b/connector-definition/template/functions.py index 44ef70c..9d46c42 100644 --- a/connector-definition/template/functions.py +++ b/connector-definition/template/functions.py @@ -13,6 +13,7 @@ from hasura_ndc.function_connector import FunctionConnector from pydantic import BaseModel # You only need this import if you plan to have complex inputs/outputs, which function similar to how frameworks like FastAPI do import asyncio # You might not need this import if you aren't doing asynchronous work +from hasura_ndc.errors import UnprocessableContent connector = FunctionConnector() @@ -99,5 +100,11 @@ async def parallel_query(name: str) -> str: await asyncio.sleep(1) return f"Hello {name}" +# This is an example of how you can throw an error +# There are different error types including: BadRequest, Forbidden, Conflict, UnprocessableContent, InternalServerError, NotSupported, and BadGateway +@connector.register_query +def error(): + raise UnprocessableContent(message="This is a error", details={"Error": "This is a error!"}) + if __name__ == "__main__": start(connector) diff --git a/connector-definition/template/requirements.txt b/connector-definition/template/requirements.txt index 23c1b6c..df3f332 100644 --- a/connector-definition/template/requirements.txt +++ b/connector-definition/template/requirements.txt @@ -9,7 +9,7 @@ fastapi==0.110.2 googleapis-common-protos==1.63.0 grpcio==1.62.2 h11==0.14.0 -hasura-ndc==0.23 +hasura-ndc==0.24 idna==3.7 importlib-metadata==7.0.0 opentelemetry-api==1.24.0