← API Security learning pathAPI Security · Module 7 of 8
Errors, logging and monitoring
See problems without leaking secrets.
📖 Key ideas
- Return clear but minimal errors to clients; never expose stack traces, SQL or internal paths.
- Use correct status codes: 400 bad input, 401 not signed in, 403 not allowed, 404 not found, 500 server error.
- Log security events: logins, failed authorisation, permission changes and admin actions.
- Never log passwords, tokens, OTPs or full card or Aadhaar numbers; mask sensitive data.
- Alert on spikes in 401/403 errors, failed logins and unusual traffic, and keep an incident plan ready.
💡 Real-life example: Good error messages are like a receptionist saying 'That room is not available': polite and clear, without handing over the building plan.
Stack traceDetailed list of code calls when an error happens
401Status code: authentication needed
403Status code: authenticated but not allowed
Audit logRecord of who did what and when