private async Task <T> RequestData <T>(string endpoint, Task <RestResponseResult> request, Func <string, T> parse) { try { EnsureAccessInformationSet(); RestResponseResult result = await request; EnsureStatusCodeOk(endpoint, result); return(parse(result.Content)); } catch (HomeyAccessException) { throw; } catch (HomeyRequestException) { throw; } catch (Exception ex) { throw new HomeyRequestException("Failed to execute request", ex) { Endpoint = endpoint }; } }
private static void EnsureStatusCodeOk(string endpoint, RestResponseResult result) { if (result.Code != HttpStatusCode.OK) { throw new HomeyRequestException("Unexpected result code") { Endpoint = endpoint, ResponseCode = result.Code }; } }