improve error handling

If the underlying model returned error instead of panicking, it
basically means the model knew what went wrong. In this case, we
should return 4xx http error as well, instead of panicking and causing
internal error.