Change add_error_handling to use a pred rather than status codes

This ticks the third box of #824. It should be reviewed after #833.

This is not yet done.

It requires transitively changing all the call sites:

- [ ] The one place where `add_error_handling` is called (making `request_func`)
- [ ] All of the places where `request_func` is called

Please keep that in mind when reviewing.