Add better handling and HTTP error codes