Implemented Error Handling in the API