Fix API return codes

The API returns 404 for almost all error states. This PR introduces more appropriate return codes which makes it easier for client developers to distinguish between the specific errors.