- added error handling and correct http status response