From the course: gRPC in Python

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Setting errors

Setting errors

- It is very important to validate incoming data. And if it's wrong, we would like to set errors. The server side context has a matter about setting the return code from the GRPC method. GRPC in general defines several status codes. It says, "okay," "cancel," and "invalid argument," which we are going to use. These are reflected in Python in the GRPC status enumeration. Let's see how it works. First, I'm creating a validate file. I'm defining a general validation error. And for the start request, I'm going to validate it, making sure the driver ID is not empty. And if you have more fields, we need to validate them as well. In the server code. Now we want to try to validate, start request. And if there is an error, we are going to log the error. We are going to set the code for invalid arguments and set the details of the error and raise the error, signaling an error. Otherwise we're going to work as usual. So, let's…

Contents