} // DownloadFile() #endregion // PUBLIC METHODS //// --------------------------------------------------------------------- #region PRIVATE METHODS /// <summary> /// Checks for errors. /// </summary> /// <param name="response">The response.</param> private static void CheckForErrors(IRestResponse response) { if ((((int)response.StatusCode) == 0) || (response.StatusCode == HttpStatusCode.OK) || (response.StatusCode == HttpStatusCode.Accepted) || (response.StatusCode == HttpStatusCode.Created)) { return; } // if if (response.StatusCode == HttpStatusCode.Unauthorized) { throw new FossologyApiException(ErrorCode.Unauthorized, response.StatusCode); } // if FossologyApiException exception; try { var result = Newtonsoft.Json.JsonConvert.DeserializeObject <Result>(response.Content); exception = new FossologyApiException( ErrorCode.RestApiError, (HttpStatusCode)result.Code, result.Message, null); } catch { exception = new FossologyApiException(ErrorCode.RestApiError); } // catch throw exception; } // CheckForErrors()
} // IsUploadUnpacked() /// <summary> /// Gets the upload with the specified id. /// </summary> /// <param name="id">The identifier.</param> /// <returns>A <see cref="Upload"/> object.</returns> public Upload GetUpload(int id) { Log.Debug($"Getting upload {id}..."); var response = this.api.Get(this.Url + $"/uploads/{id}", true); if (response.StatusCode == HttpStatusCode.OK) { var upload = JsonConvert.DeserializeObject <Upload>( response.Content, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, }); return(upload); } // if // this will be the case for StatusCode == ServiceUnavailable // In this case header["look-at"] contains something like /api/v1/jobs?upload=8 var result = JsonConvert.DeserializeObject <Result>(response.Content); var exception = new FossologyApiException( ErrorCode.RestApiError, (HttpStatusCode)result.Code, result.Message, null); throw exception; } // GetUpload()