RestApi: improved error handling