Fix misleading permission errors in the API
A server configuration problem, such as missing file storage settings on a self-hosted instance, made every API request answer "You don't have permission to perform this action", which pointed to the wrong cause.
- Fixed the API so that only real authorization failures are reported as permission errors.
- Improved server logs, which now record the original cause of an unexpected API error.
