Improve error handling of web api