Skip to main content

Error handling

The Petstore API uses conventional HTTP status codes. Codes in the 2xx range indicate success, 4xx indicate a client error, and 5xx indicate a server error.

For the three playground GET operations, see response tables in petstore-playground.json (invalid status on findByStatus, login failures, and server errors).

HTTP status codes​

CodeMeaning
200Success
400Bad request. Check your parameters.
401Unauthorized. Invalid or missing credentials.
404Resource not found (pet, order, or user).
422Validation exception. Invalid input.
500Server error. Retry with exponential backoff.

Validation errors​

Invalid input often returns 400 or 422 with a JSON body:

{
"code": 400,
"type": "error",
"message": "Invalid ID supplied"
}

Playground-oriented examples​

Invalid status on find by status​

curl -w "\nHTTP %{http_code}\n" "https://petstore3.swagger.io/api/v3/pet/findByStatus?status=invalid"

Login failure (bad password)​

curl -w "\nHTTP %{http_code}\n" "https://petstore3.swagger.io/api/v3/user/login?username=theUser&password=wrong"

Handling errors in code​

const res = await fetch(
'https://petstore3.swagger.io/api/v3/pet/findByStatus?status=available',
);
if (!res.ok) {
if (res.status === 400) {
const err = await res.json();
console.log(`Bad request: ${err.message}`);
}
}

Other operations on the sample server​

Endpoints such as store orders or pet updates can return additional error patterns. Those operations are not described in the playground OpenAPI file.