https://dagster.io/ logo
Title
m

Martin Carlsson

10/18/2021, 11:37 AM
I’m trying to setup error handling in dagster I’m new to dagster, and not a Python expert In my first solid I calling an API. What I want is, if the response code is anything other than 200, I want to log response code and stop the entire pipeline. There is no need to run the rest is I don’t get a 200 How do I do that?
r

raaid

10/18/2021, 12:05 PM
If you're okay with defining the non-200 response as an error case, you could do something like this:
@solid
def my_solid(context):
    # your code
    response = requests.get("<http://fakewebsite.com|fakewebsite.com>")

    if response.status_code != 200:
        # if additional logging desired, add here
        raise requests.HTTPError(f"Got non-200 response: {response.status_code}")
Might be a better way to do it but this is a fairly simple way that comes to mind. The error would stop the rest of the pipeline from executing.
m

Martin Carlsson

10/18/2021, 12:06 PM
@raaid Thanks - just what I needed
❤️ 1
m

max

10/18/2021, 3:19 PM
you can also raise
dagster.Failure
m

Martin Carlsson

10/18/2021, 3:21 PM
Thanks. This looks a bit more Dagster’ish - I’ll try it out
Works nicely it is great that I can add metadata
😛artydagster: 2