senior-ish dev building an API every time I need to return an auth error I open a tab to check 401? 403? 404? I have done this for years the tab is always the same article
Please just tell me the rule, once, in a way that I will remember.
senior-ish dev building an API every time I need to return an auth error I open a tab to check 401? 403? 404? I have done this for years the tab is always the same article
Please just tell me the rule, once, in a way that I will remember.
401 = "I do not know who you are" (it is badly named; it means unauthenticated). The response should carry a WWW-Authenticate header saying how to authenticate.
403 = "I know who you are, and you may not do this".
Memory trick: 401 -> log in and try again. 403 -> logging in again will not help.
404 is a legit third choice when even admitting the resource exists would leak information (private repos, other tenants' ids). Pick one policy and apply it everywhere, or the difference between 403 and 404 becomes the leak.
I have done this for years
Welcome to the club. We have a laminated card.