Stay organized with collectionsSave and categorize content based on your preferences.
This page lists the exceptions provided by theendpointslibrary as well as
HTTP status codes supported by Cloud Endpoints Frameworks.
In many situations, you might 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 doesn't exist, you might want to send an
HTTP404status code to say that no entity exists with ID:entityId.
You can send common HTTP status codes by throwing an exception provided
by theendpointslibrary as follows:
thrownewNotFoundException(user.getEmail());
Exceptions provided by Endpoints Frameworks
Endpoints Frameworks provides the following exceptions, corresponding
to specific HTTP status codes:
Cloud Endpoints Frameworks supports a subset of HTTP status codes
in API responses. The following table describes the supported codes.
HTTP status codes
Support
HTTP 2xx
HTTP200is typically assumed by Endpoints Frameworks if the API method returns successfully.If the API method response type isvoidor the return value of the API method isnull, HTTP204is set instead.
HTTP 3xx
HTTP 3xx codes aren't supported. Use of any HTTP 3xx codes results in an HTTP404response.
HTTP 4xx
Only the following HTTP 4xx codes are supported:
400
401
403
404
409
410
412
413
Any other HTTP 4xx codes are returned as error404, except for the following:
405is returned as501
408is returned as503
HTTP 5xx
All HTTP 5xx status codes are converted to HTTP503in the client response.
Creating your own exception classes
If you want to create other exception classes for other HTTP status codes, you
need to subclasscom.google.api.server.spi.ServiceException. The
following snippet shows how to create an exception class that represents an
HTTP408status code:
importcom.google.api.server.spi.ServiceException;// Exceptions must inherit from ServiceExceptionpublicclassRequestTimeoutExceptionextendsServiceException{publicRequestTimeoutException(Stringmessage){super(408,message);}}
Using unsupported HTTP status codes
It is possible to use HTTP status codes that aren't in the preceding supported
list. Note that if you decide to do so, it might have unintended consequences
for client libraries that access the API. To use unsupported error codes,
create your own exception class, as described in the previous section, and
add a new servlet initialization parameterenableExceptionCompatibilitytoEndpointsServlet:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eendpoints\u003c/code\u003e library provides exceptions that correspond to common HTTP status codes, allowing developers to indicate the success or failure of API requests.\u003c/p\u003e\n"],["\u003cp\u003eEndpoints Frameworks offers built-in exception classes for HTTP status codes like \u003ccode\u003e400\u003c/code\u003e, \u003ccode\u003e401\u003c/code\u003e, \u003ccode\u003e403\u003c/code\u003e, \u003ccode\u003e404\u003c/code\u003e, \u003ccode\u003e409\u003c/code\u003e, \u003ccode\u003e500\u003c/code\u003e, and \u003ccode\u003e503\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eHTTP \u003ccode\u003e200\u003c/code\u003e and \u003ccode\u003e204\u003c/code\u003e are supported for successful API methods, while HTTP 3xx codes are not supported and will result in an HTTP \u003ccode\u003e404\u003c/code\u003e response.\u003c/p\u003e\n"],["\u003cp\u003eWhile a subset of HTTP 4xx codes are directly supported, many others are converted to \u003ccode\u003e404\u003c/code\u003e, and all HTTP 5xx codes are converted to \u003ccode\u003e503\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can create custom exception classes for unsupported HTTP status codes by subclassing \u003ccode\u003ecom.google.api.server.spi.ServiceException\u003c/code\u003e and enabling \u003ccode\u003eenableExceptionCompatibility\u003c/code\u003e in the \u003ccode\u003eEndpointsServlet\u003c/code\u003e configuration.\u003c/p\u003e\n"]]],[],null,["# Exceptions and HTTP status codes\n\nThis page lists the exceptions provided by the `endpoints` library as well as\nHTTP status codes supported by Cloud Endpoints Frameworks.\n\nIn many situations, you might want to use common HTTP status codes to indicate\nthe success or failure of a user's API request. For example, if a user is\nattempting to retrieve an entity which doesn't exist, you might want to send an\nHTTP `404` status code to say that no entity exists with ID: `entityId`.\n\nYou can send common HTTP status codes by throwing an exception provided\nby the `endpoints` library as follows: \n\n throw new NotFoundException(user.getEmail());\n\nExceptions provided by Endpoints Frameworks\n-------------------------------------------\n\nEndpoints Frameworks provides the following exceptions, corresponding\nto specific HTTP status codes:\n\nSupported HTTP status codes\n---------------------------\n\nCloud Endpoints Frameworks supports a subset of HTTP status codes\nin API responses. The following table describes the supported codes.\n\n| **Important:** Don't use custom exception classes to return HTTP 2xx codes. Endpoints Frameworks doesn't support returning HTTP `201` or any other 2xx codes except HTTP `200` and HTTP `204` as described in the preceding table.\n\nCreating your own exception classes\n-----------------------------------\n\nIf you want to create other exception classes for other HTTP status codes, you\nneed to subclass `com.google.api.server.spi.ServiceException`. The\nfollowing snippet shows how to create an exception class that represents an\nHTTP `408` status code: \n\n import com.google.api.server.spi.ServiceException;\n\n // Exceptions must inherit from ServiceException\n public class RequestTimeoutException extends ServiceException {\n public RequestTimeoutException(String message) {\n super(408, message);\n }\n }\n\n| **Important:** An uncaught exception in your application results in an HTTP `503` error from your Cloud Endpoints API, unless it extends `com.google.api.server.spi.ServiceException`.\n\nUsing unsupported HTTP status codes\n-----------------------------------\n\nIt is possible to use HTTP status codes that aren't in the preceding supported\nlist. Note that if you decide to do so, it might have unintended consequences\nfor client libraries that access the API. To use unsupported error codes,\ncreate your own exception class, as described in the previous section, and\nadd a new servlet initialization parameter `enableExceptionCompatibility` to\n`EndpointsServlet`: \n\n \u003cservlet\u003e\n \u003cservlet-name\u003ecom.google.api.server.spi.EndpointsServlet\u003c/servlet-name\u003e\n \u003cservlet-class\u003ecom.google.api.server.spi.EndpointsServlet\u003c/servlet-class\u003e\n \u003cinit-param\u003e\n \u003cparam-name\u003eservices\u003c/param-name\u003e\n \u003cparam-value\u003e...\u003c/param-value\u003e\n \u003c/init-param\u003e\n \u003cinit-param\u003e\n \u003cparam-name\u003eenableExceptionCompatibility\u003c/param-name\u003e\n \u003cparam-value\u003etrue\u003c/param-value\u003e\n \u003c/init-param\u003e\n \u003c/servlet\u003e"]]