Google App Engine
Feedback on this document

Endpoints Exceptions

In many situations, you may want to use common HTTP status codes to indicate the success or failure of a user's API request. For example, if a user is attempting to retrieve an entity which does not exist, you may want to send an HTTP 404 status code saying No entity with the ID entity_id exists.

Important: An uncaught exception in your application will result in a 503 error from your Endpoints API.

You can send such common HTTP status codes by raising an exception provided by the endpoints library as follows:

message = 'No entity with the id "%s" exists.' % entity_id
raise endpoints.NotFoundException(message)

Exceptions Provided by Endpoints

The endpoints library provides the following exceptions, corresponding to specific HTTP status codes:

Exception Corresponding HTTP Status Code
endpoints.BadRequestException HTTP 400
endpoints.UnauthorizedException HTTP 401
endpoints.ForbiddenException HTTP 403
endpoints.NotFoundException HTTP 404
endpoints.InternalServerErrorException HTTP 500

Creating Your Own Exception Classes

If you want to create other exception classes for other HTTP status codes, you can do so by subclassing endpoints.ServiceException.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.