Proper error handling and HTTP error codes