Understanding API Errors
API errors fall into four broad categories, each with different root causes and fixes:
| Error type | What it means | Typical cause |
|---|---|---|
| API timeout error | Request took too long and was abandoned | Slow query, overloaded server, network latency |
| API not responding | No response received at all | Server down, firewall blocking, wrong URL |
| API returns 500 error | Server encountered an unhandled exception | Code bug, missing config, database error |
| Endpoint not responding | Specific route returns no response | Route not deployed, misconfigured proxy |
API Timeout Error
An api timeout error occurs when a request exceeds the configured timeout threshold. The client gives up waiting and returns an error — even if the server eventually processes the request.
Common causes
- Slow database queries (missing indexes, N+1 queries, full table scans)
- External service calls (payment gateway, email provider) taking too long
- Server CPU or memory saturation under load
- Network latency between client and server
- Timeout configured too low for the operation
Diagnosis
# Check slow queries in MySQL
SELECT query, exec_count, avg_latency
FROM sys.statement_analysis
ORDER BY avg_latency DESC
LIMIT 10;
# Check server load
top -b -n1 | head -20
# Test endpoint response time with curl
curl -w "\nTime: %{time_total}s\n" -o /dev/null -s https://api.example.com/endpointFixes
- Add database indexes on columns used in WHERE clauses and JOINs
- Move long-running operations to background jobs (queues)
- Add caching for expensive read operations (Redis, Memcached)
- Increase timeout thresholds if the operation legitimately takes time
- Scale server resources (vertical or horizontal) if under load
API Not Responding
When an api not responding error occurs, the client receives no response at all — not even an error code. The connection either hangs or is immediately refused.
Diagnosis steps
# Check if the server is reachable
ping api.example.com
# Check if the port is open
nc -zv api.example.com 443
# Check if the service is running (Linux)
systemctl status your-api-service
# Check listening ports
ss -tlnp | grep :443Common fixes
- Restart the API service if it is deadlocked or crashed
- Check firewall rules — ensure the port is open to the client's IP
- Verify the correct URL and port are being used
- Check SSL certificate validity if using HTTPS
- Review application logs for out-of-memory or crash errors
API Returns 500 Error
A 500 Internal Server Error means the server encountered an unhandled exception. The api returns 500 error is always a server-side bug — the client request is valid, but the server failed to process it.
Finding the root cause
# View recent application logs (Node.js example)
journalctl -u your-api.service -n 100 --no-pager
# View Nginx error log
tail -50 /var/log/nginx/error.log
# View application error log
tail -50 /var/log/your-app/error.logCommon causes and fixes
| Cause | Fix |
|---|---|
| Unhandled exception in code | Add try/catch blocks; review stack trace in logs |
| Missing environment variable | Check all required env vars are set in production |
| Database connection failure | Verify DB credentials, connection pool limits, and DB server status |
| Out of memory | Increase server memory or fix memory leak in code |
| Dependency not installed | Run npm install / pip install in production environment |
| File permission error | Ensure the app user has read/write access to required directories |
Endpoint Not Responding
An endpoint not responding issue is specific to one route while others work. This narrows the problem to the route definition, middleware, or a specific handler.
Diagnosis
# Test the specific endpoint directly
curl -v https://api.example.com/v1/specific-endpoint
# Compare with a working endpoint
curl -v https://api.example.com/v1/health
# Check if the route is registered (Express.js example)
node -e "const app = require('./app'); app._router.stack.forEach(r => r.route && console.log(r.route.path))"
Common causes
- Route not deployed — new code not pushed to production
- Middleware blocking the request before it reaches the handler
- Reverse proxy (Nginx, Apache) not forwarding the path correctly
- Route defined after a catch-all route that intercepts it first
- CORS policy blocking the request from the browser
Diagnosis Checklist
Proactive API Monitoring
The best way to handle API errors is to detect them before your users do. Alive24x7 can monitor any HTTP/HTTPS endpoint every minute from 13 global locations and alert you the moment it returns a timeout, 500, or any unexpected status code.
What Alive24x7 monitors for APIs
- HTTP status code (alert if not 200, or any custom code)
- Response time (alert if exceeds threshold)
- Response body keyword (confirm the API returns expected data)
- SSL certificate expiry (alert 30/14/7 days before expiry)
- Multi-region checks (detect regional outages)
Frequently Asked Questions
What is the difference between a timeout and a connection refused error?▼
A timeout means the connection was established but the server took too long to respond. A connection refused error means the server actively rejected the connection — usually because nothing is listening on that port.
My API works locally but not in production. Why?▼
Common causes: missing environment variables in production, firewall rules blocking the port, a different database or service URL, or the production server not having the latest code deployed.
How do I set a timeout on API requests in JavaScript?▼
Use AbortController with fetch: create a controller, call setTimeout to invoke controller.abort() after your desired timeout, and pass the signal to your fetch call. Catch AbortError to handle the timeout case.
How often should I monitor my API endpoints?▼
Every minute is the standard for production APIs. Alive24x7 checks every minute by default, which means you will know about an outage within 60 seconds of it starting.