This block looks like too much code copied from service.error.preprocess_request - maybe refactor that one and re-use it here?