← API Security learning path
API Security · Module 7 of 8

Errors, logging and monitoring

See problems without leaking secrets.

📖 Key ideas

  1. Return clear but minimal errors to clients; never expose stack traces, SQL or internal paths.
  2. Use correct status codes: 400 bad input, 401 not signed in, 403 not allowed, 404 not found, 500 server error.
  3. Log security events: logins, failed authorisation, permission changes and admin actions.
  4. Never log passwords, tokens, OTPs or full card or Aadhaar numbers; mask sensitive data.
  5. 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