Add error checking when creating the API