/// <summary> /// Parses the BoxResponse with the provided converter /// </summary> /// <typeparam name="T">The return type of the Box response</typeparam> /// <param name="response">The response to parse</param> /// <param name="converter">The converter to use for the conversion</param> /// <returns></returns> public static IBoxResponse <T> ParseResults <T>(this IBoxResponse <T> response, IBoxConverter converter) where T : class { BoxException exToThrow = null; switch (response.Status) { case ResponseStatus.Success: if (!string.IsNullOrWhiteSpace(response.ContentString)) { response.ResponseObject = converter.Parse <T>(response.ContentString); } break; default: if (!string.IsNullOrWhiteSpace(response.ContentString)) { try { switch (response.StatusCode) { case System.Net.HttpStatusCode.Conflict: BoxConflictError <T> error = converter.Parse <BoxConflictError <T> >(response.ContentString); exToThrow = new BoxConflictException <T>(response.ContentString, error); break; default: response.Error = converter.Parse <BoxError>(response.ContentString); break; } } catch (Exception) { Debug.WriteLine(string.Format("Unable to parse error message: {0}", response.ContentString)); } throw exToThrow == null ? new BoxException(response.ContentString, response.Error) { StatusCode = response.StatusCode } : exToThrow; } throw new BoxException(response.ContentString) { StatusCode = response.StatusCode }; } return(response); }
/// <summary> /// Parses the BoxResponse with the provided converter /// </summary> /// <typeparam name="T">The return type of the Box response</typeparam> /// <param name="response">The response to parse</param> /// <param name="converter">The converter to use for the conversion</param> /// <returns></returns> public static IBoxResponse <T> ParseResults <T>(this IBoxResponse <T> response, IBoxConverter converter) where T : class { BoxException exToThrow = null; switch (response.Status) { case ResponseStatus.Success: if (!string.IsNullOrWhiteSpace(response.ContentString)) { response.ResponseObject = converter.Parse <T>(response.ContentString); } break; case ResponseStatus.Forbidden: var errorMsg = response.Headers.WwwAuthenticate.FirstOrDefault(); if (errorMsg != null) { var err = new BoxError() { Code = response.StatusCode.ToString(), Description = "Forbidden", Message = errorMsg.ToString() }; throw new BoxException(err.Message, err); } else if (!string.IsNullOrWhiteSpace(response.ContentString)) { response.Error = converter.Parse <BoxError>(response.ContentString); throw new BoxException(response.ContentString, response.Error) { StatusCode = response.StatusCode }; } else { throw new BoxException("Forbidden"); } default: if (!string.IsNullOrWhiteSpace(response.ContentString)) { try { switch (response.StatusCode) { case System.Net.HttpStatusCode.Conflict: if (response is IBoxResponse <BoxPreflightCheck> ) { BoxPreflightCheckConflictError <BoxFile> err = converter.Parse <BoxPreflightCheckConflictError <BoxFile> >(response.ContentString); exToThrow = new BoxPreflightCheckConflictException <BoxFile>(response.ContentString, err); } else { BoxConflictError <T> error = converter.Parse <BoxConflictError <T> >(response.ContentString); exToThrow = new BoxConflictException <T>(response.ContentString, error); } break; default: response.Error = converter.Parse <BoxError>(response.ContentString); break; } } catch (Exception ex) { Debug.WriteLine(string.Format("Unable to parse error message: {0}", response.ContentString)); } throw exToThrow == null ? new BoxException(response.ContentString, response.Error) { StatusCode = response.StatusCode } : exToThrow; } throw new BoxException(response.ContentString) { StatusCode = response.StatusCode }; } return(response); }
public BoxConflictException(string message, BoxConflictError <T> error) : base(message, error) { _conflictError = error; }
protected internal BoxConflictException(string message, BoxConflictError <T> error, HttpStatusCode statusCode, HttpResponseHeaders responseHeaders) : base(message, error, statusCode, responseHeaders) { _conflictError = error; }