public static B2Exception GetExceptionForError(B2ErrorResponseOutputDTO error) { switch (error.Status) { case 400: if (error.Message == "Sha1 did not match data received") { return(new B2HashMismatchException(error)); } else { return(new B2Exception(error)); } case 401: throw new B2BadAuthTokenException(error); case 503: if (error.Code == "service_unavailable") { return(new B2ServerBusyException(error)); } else { return(new B2Exception(error)); } default: return(new B2Exception(error)); } }
/// <summary> /// Can an upload potentially be recovered by retrying after supplied error /// </summary> public static bool IsRecoverableError(B2ErrorResponseOutputDTO error) { var exception = GetExceptionForError(error); if (exception is B2HashMismatchException) { return(true); } else if (exception is B2BadAuthTokenException) { return(true); } else if (exception is B2ServerBusyException) { return(true); } return(false); }
public static void ThrowException(B2ErrorResponseOutputDTO error) { throw GetExceptionForError(error); }
public static void ThrowException(string errorJson) { B2ErrorResponseOutputDTO error = JsonSerializer.Deserialize <B2ErrorResponseOutputDTO>(errorJson); throw GetExceptionForError(error); }
public B2HashMismatchException(B2ErrorResponseOutputDTO error) : base(error) { }
public B2ServerBusyException(B2ErrorResponseOutputDTO error) : base(error) { }
public B2Exception(B2ErrorResponseOutputDTO error) : base(error.ToString()) { }
public B2BadAuthTokenException(B2ErrorResponseOutputDTO error) : base(error) { }