Fix error handling

because in some cases the error is a dict