public override AmazonServiceException UnmarshallException(JsonUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode) { ErrorResponse errorResponse = JsonErrorResponseUnmarshaller.GetInstance().Unmarshall(context); if (errorResponse.Code != null && errorResponse.Code.Equals("AccessDeniedException")) { AccessDeniedException ex = new AccessDeniedException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode); return(ex); } if (errorResponse.Code != null && errorResponse.Code.Equals("InternalServiceException")) { InternalServiceException ex = new InternalServiceException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode); return(ex); } if (errorResponse.Code != null && errorResponse.Code.Equals("ValidationException")) { ValidationException ex = new ValidationException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode); return(ex); } if (errorResponse.Code != null && errorResponse.Code.Equals("IncompatibleVersionException")) { IncompatibleVersionException ex = new IncompatibleVersionException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode); return(ex); } return(new AmazonElasticTranscoderException(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode)); }
private static Task HandleAccessDeniedExceptionAsync(HttpContext context, AccessDeniedException ex) { context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; ApiResponseDto errorDetails = new() { StatusCode = context.Response.StatusCode, Message = ex.Message }; return(DefaultContextResponseSend(context, errorDetails)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsNotWritable() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsNotWritable() { Path archive = _testDirectory.file("the-archive.dump").toPath(); Path destination = _testDirectory.directory("subdir/the-destination").toPath(); Files.createDirectories(destination.Parent); using (System.IDisposable ignored = withPermissions(destination.Parent, emptySet())) { AccessDeniedException exception = assertThrows(typeof(AccessDeniedException), () => (new Loader()).load(archive, destination, destination)); assertEquals(destination.Parent.ToString(), exception.Message); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) void shouldGiveAClearErrorMessageIfTheArchivesParentDirectoryIsNotWritable() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldGiveAClearErrorMessageIfTheArchivesParentDirectoryIsNotWritable() { Path directory = _testDirectory.directory("a-directory").toPath(); Path archive = _testDirectory.file("subdir/the-archive.dump").toPath(); Files.createDirectories(archive.Parent); using (System.IDisposable ignored = TestUtils.WithPermissions(archive.Parent, emptySet())) { AccessDeniedException exception = assertThrows(typeof(AccessDeniedException), () => (new Dumper()).dump(directory, directory, archive, GZIP, Predicates.alwaysFalse())); assertEquals(archive.Parent.ToString(), exception.Message); } }
/// <summary> /// Get information from a range in a spreadsheet /// </summary> /// <param name="spreadSheetId">Source spreadsheet ID</param> /// <param name="readRange">Range with information</param> /// <returns>Requested information</returns> /// <exception cref="AccessDeniedException">Thrown when had problem with there was an access problem with Google Drive</exception> private async Task <IList <IList <object> > > ReadInfoAsync(string spreadSheetId, string readRange) { try { var response = await _service.Spreadsheets.Values. Get(spreadSheetId, readRange).ExecuteAsync(); return(response?.Values); } catch (Exception e) { throw AccessDeniedException.CreateException(e); } }
/// <summary> /// Write information to a range in a spreadsheet /// </summary> /// <param name="info">Information to write</param> /// <param name="spreadSheetId">Source spreadsheet ID</param> /// <param name="writeRange">Range to write</param> /// <exception cref="AccessDeniedException">Thrown when had problem with there was an access problem with Google Drive</exception> private async Task WriteInfoAsync(IList <IList <object> > info, string spreadSheetId, string writeRange) { try { var valueRange = new ValueRange { Values = info }; var update = _service.Spreadsheets.Values.Update(valueRange, spreadSheetId, writeRange); update.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; await update.ExecuteAsync(); } catch (Exception e) { throw AccessDeniedException.CreateException(e); } }
private static void ParseWellKnownErrorNoContent(IRestResponse response) { MinioException error = null; ErrorResponse errorResponse = new ErrorResponse(); foreach (Parameter parameter in response.Headers) { if (parameter.Name.Equals("x-amz-id-2", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.HostId = parameter.Value.ToString(); } if (parameter.Name.Equals("x-amz-request-id", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.RequestId = parameter.Value.ToString(); } if (parameter.Name.Equals("x-amz-bucket-region", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.BucketRegion = parameter.Value.ToString(); } } errorResponse.Resource = response.Request.Resource; // zero, one or two segments var resourceSplits = response.Request.Resource.Split(new[] { '/' }, 2, StringSplitOptions.RemoveEmptyEntries); if (HttpStatusCode.NotFound.Equals(response.StatusCode)) { int pathLength = resourceSplits.Length; bool isAWS = response.ResponseUri.Host.EndsWith("s3.amazonaws.com"); bool isVirtual = isAWS && !response.ResponseUri.Host.StartsWith("s3.amazonaws.com"); if (pathLength > 1) { var objectName = resourceSplits[1]; errorResponse.Code = "NoSuchKey"; error = new ObjectNotFoundException(objectName, "Not found."); } else if (pathLength == 1) { var resource = resourceSplits[0]; if (isAWS && isVirtual && response.Request.Resource != string.Empty) { errorResponse.Code = "NoSuchKey"; error = new ObjectNotFoundException(resource, "Not found."); } else { errorResponse.Code = "NoSuchBucket"; BucketRegionCache.Instance.Remove(resource); error = new BucketNotFoundException(resource, "Not found."); } } else { error = new InternalClientException("404 without body resulted in path with less than two components", response); } } else if (HttpStatusCode.BadRequest.Equals(response.StatusCode)) { int pathLength = resourceSplits.Length; if (pathLength > 1) { var objectName = resourceSplits[1]; errorResponse.Code = "InvalidObjectName"; error = new InvalidObjectNameException(objectName, "Invalid object name."); } else { error = new InternalClientException("400 without body resulted in path with less than two components", response); } } else if (HttpStatusCode.Forbidden.Equals(response.StatusCode)) { errorResponse.Code = "Forbidden"; error = new AccessDeniedException("Access denied on the resource: " + response.Request.Resource); } error.Response = errorResponse; throw error; }
/// <summary> /// Parse response errors if any and return relevant error messages /// </summary> /// <param name="response"></param> internal static void ParseError(IRestResponse response) { if (response == null) { throw new ConnectionException("Response is nil. Please report this issue https://github.com/minio/minio-dotnet/issues"); } if (HttpStatusCode.Redirect.Equals(response.StatusCode) || HttpStatusCode.TemporaryRedirect.Equals(response.StatusCode) || HttpStatusCode.MovedPermanently.Equals(response.StatusCode)) { throw new RedirectionException("Redirection detected. Please report this issue https://github.com/minio/minio-dotnet/issues"); } if (string.IsNullOrWhiteSpace(response.Content)) { ErrorResponse errorResponse = new ErrorResponse(); if (HttpStatusCode.Forbidden.Equals(response.StatusCode) || HttpStatusCode.NotFound.Equals(response.StatusCode) || HttpStatusCode.MethodNotAllowed.Equals(response.StatusCode) || HttpStatusCode.NotImplemented.Equals(response.StatusCode)) { MinioException e = null; foreach (Parameter parameter in response.Headers) { if (parameter.Name.Equals("x-amz-id-2", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.HostId = parameter.Value.ToString(); } if (parameter.Name.Equals("x-amz-request-id", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.RequestId = parameter.Value.ToString(); } if (parameter.Name.Equals("x-amz-bucket-region", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.BucketRegion = parameter.Value.ToString(); } } errorResponse.Resource = response.Request.Resource; if (HttpStatusCode.NotFound.Equals(response.StatusCode)) { int pathLength = response.Request.Resource.Split('/').Count(); bool isAWS = response.ResponseUri.Host.EndsWith("s3.amazonaws.com"); bool isVirtual = isAWS && !(response.ResponseUri.Host.StartsWith("s3.amazonaws.com")); if (pathLength > 1) { errorResponse.Code = "NoSuchKey"; var bucketName = response.Request.Resource.Split('/')[0]; var objectName = response.Request.Resource.Split('/')[1]; if (objectName == "") { e = new BucketNotFoundException(bucketName, "Not found."); } else { e = new ObjectNotFoundException(objectName, "Not found."); } } else if (pathLength == 1) { var resource = response.Request.Resource.Split('/')[0]; if (isAWS && isVirtual && response.Request.Resource != "") { errorResponse.Code = "NoSuchKey"; e = new ObjectNotFoundException(resource, "Not found."); } else { errorResponse.Code = "NoSuchBucket"; BucketRegionCache.Instance.Remove(resource); e = new BucketNotFoundException(resource, "Not found."); } } else { e = new InternalClientException("404 without body resulted in path with less than two components"); } } else if (HttpStatusCode.Forbidden.Equals(response.StatusCode)) { errorResponse.Code = "Forbidden"; e = new AccessDeniedException("Access denied on the resource: " + response.Request.Resource); } e.Response = errorResponse; throw e; } throw new InternalClientException("Unsuccessful response from server without XML error: " + response.ErrorMessage); } if (response.StatusCode.Equals(HttpStatusCode.NotFound) && response.Request.Resource.EndsWith("?location") && response.Request.Method.Equals(Method.GET)) { var bucketName = response.Request.Resource.Split('?')[0]; BucketRegionCache.Instance.Remove(bucketName); throw new BucketNotFoundException(bucketName, "Not found."); } var contentBytes = System.Text.Encoding.UTF8.GetBytes(response.Content); var stream = new MemoryStream(contentBytes); ErrorResponse errResponse = (ErrorResponse)(new XmlSerializer(typeof(ErrorResponse)).Deserialize(stream)); // Handle XML response for Bucket Policy not found case if (response.StatusCode.Equals(HttpStatusCode.NotFound) && response.Request.Resource.EndsWith("?policy") && response.Request.Method.Equals(Method.GET) && (errResponse.Code.Equals("NoSuchBucketPolicy"))) { ErrorResponseException ErrorException = new ErrorResponseException(errResponse.Message, errResponse.Code); ErrorException.Response = errResponse; ErrorException.XmlError = response.Content; throw ErrorException; } MinioException MinioException = new MinioException(errResponse.Message); MinioException.Response = errResponse; MinioException.XmlError = response.Content; throw MinioException; }
private ClientException ParseError(IRestResponse response) { if (response == null) { return(new ConnectionException()); } if (HttpStatusCode.Redirect.Equals(response.StatusCode) || HttpStatusCode.TemporaryRedirect.Equals(response.StatusCode) || HttpStatusCode.MovedPermanently.Equals(response.StatusCode)) { return(new RedirectionException()); } if (string.IsNullOrWhiteSpace(response.Content)) { if (HttpStatusCode.Forbidden.Equals(response.StatusCode) || HttpStatusCode.NotFound.Equals(response.StatusCode) || HttpStatusCode.MethodNotAllowed.Equals(response.StatusCode) || HttpStatusCode.NotImplemented.Equals(response.StatusCode)) { ClientException e = null; ErrorResponse errorResponse = new ErrorResponse(); foreach (Parameter parameter in response.Headers) { if (parameter.Name.Equals("x-amz-id-2", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.HostID = parameter.Value.ToString(); } if (parameter.Name.Equals("x-amz-request-id", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.RequestID = parameter.Value.ToString(); } } errorResponse.Resource = response.Request.Resource; if (HttpStatusCode.NotFound.Equals(response.StatusCode)) { int pathLength = response.Request.Resource.Split('/').Count(); if (pathLength > 1) { errorResponse.Code = "NoSuchKey"; e = new ObjectNotFoundException(); } else if (pathLength == 1) { errorResponse.Code = "NoSuchBucket"; e = new BucketNotFoundException(); } else { e = new InternalClientException("404 without body resulted in path with less than two components"); } } else if (HttpStatusCode.Forbidden.Equals(response.StatusCode)) { errorResponse.Code = "Forbidden"; e = new AccessDeniedException(); } else if (HttpStatusCode.MethodNotAllowed.Equals(response.StatusCode)) { errorResponse.Code = "MethodNotAllowed"; e = new MethodNotAllowedException(); } else { errorResponse.Code = "MethodNotAllowed"; e = new MethodNotAllowedException(); } e.Response = errorResponse; return(e); } throw new InternalClientException("Unsuccessful response from server without XML error: " + response.StatusCode); } var contentBytes = System.Text.Encoding.UTF8.GetBytes(response.Content); var stream = new MemoryStream(contentBytes); ErrorResponse errResponse = (ErrorResponse)(new XmlSerializer(typeof(ErrorResponse)).Deserialize(stream)); string code = errResponse.Code; ClientException clientException; if ("NoSuchBucket".Equals(code)) { clientException = new BucketNotFoundException(); } else if ("NoSuchKey".Equals(code)) { clientException = new ObjectNotFoundException(); } else if ("InvalidBucketName".Equals(code)) { clientException = new InvalidKeyNameException(); } else if ("InvalidObjectName".Equals(code)) { clientException = new InvalidKeyNameException(); } else if ("AccessDenied".Equals(code)) { clientException = new AccessDeniedException(); } else if ("InvalidAccessKeyId".Equals(code)) { clientException = new AccessDeniedException(); } else if ("BucketAlreadyExists".Equals(code)) { clientException = new BucketExistsException(); } else if ("ObjectAlreadyExists".Equals(code)) { clientException = new ObjectExistsException(); } else if ("InternalError".Equals(code)) { clientException = new InternalServerException(); } else if ("KeyTooLong".Equals(code)) { clientException = new InvalidKeyNameException(); } else if ("TooManyBuckets".Equals(code)) { clientException = new MaxBucketsReachedException(); } else if ("PermanentRedirect".Equals(code)) { clientException = new RedirectionException(); } else if ("MethodNotAllowed".Equals(code)) { clientException = new ObjectExistsException(); } else if ("BucketAlreadyOwnedByYou".Equals(code)) { clientException = new BucketExistsException(); } else { clientException = new InternalClientException(errResponse.ToString()); } clientException.Response = errResponse; clientException.XmlError = response.Content; return(clientException); }
// Token: 0x06000983 RID: 2435 RVA: 0x00021474 File Offset: 0x0001F674 private static ErrorInformation GetExceptionHandlingInformation(Exception exception, RequestContext requestContext) { bool sendWatsonReport = false; Strings.IDs? messageId = null; string messageParameter = null; string lids = null; SupportLevel? supportLevel = null; IMailboxContext mailboxContext = (requestContext != null) ? requestContext.UserContext : null; string text = string.Empty; if (mailboxContext != null) { text = mailboxContext.PrimarySmtpAddress.ToString(); } string message; if (exception is OwaNotSupportedException) { message = exception.Message; } else if (exception is OwaIdentityException) { sendWatsonReport = false; message = exception.Message; } else if (exception is OwaExistentNotificationPipeException) { message = Strings.GetLocalizedString(1295605912); messageId = new Strings.IDs?(1295605912); } else if (exception is OwaNotificationPipeException) { message = Strings.GetLocalizedString(-771052428); messageId = new Strings.IDs?(-771052428); sendWatsonReport = false; } else if (exception is OwaOperationNotSupportedException) { message = exception.Message; } else if (exception is OwaADObjectNotFoundException) { OwaADUserNotFoundException ex = exception as OwaADUserNotFoundException; supportLevel = new SupportLevel?(SupportLevel.TenantAdmin); if (ex != null && !string.IsNullOrWhiteSpace(ex.UserName)) { message = string.Format(Strings.GetLocalizedString(-765910865), ex.UserName); messageId = new Strings.IDs?(-765910865); messageParameter = ex.UserName; } else { message = Strings.GetLocalizedString(-950823100); messageId = new Strings.IDs?(-950823100); } } else if (exception is OwaLockTimeoutException || exception is BailOutException) { message = Strings.GetLocalizedString(-116001901); messageId = new Strings.IDs?(-116001901); if (requestContext != null) { requestContext.HttpContext.Response.AppendToLog("&s=ReqTimeout"); } } else if (exception is ObjectExistedException) { message = Strings.GetLocalizedString(-1399945920); messageId = new Strings.IDs?(-1399945920); } else if (exception is MailboxInSiteFailoverException) { sendWatsonReport = false; message = Strings.GetLocalizedString(26604436); messageId = new Strings.IDs?(26604436); supportLevel = new SupportLevel?(SupportLevel.Transient); } else if (exception is MailboxCrossSiteFailoverException || exception is WrongServerException) { sendWatsonReport = false; message = Strings.GetLocalizedString(26604436); messageId = new Strings.IDs?(26604436); supportLevel = new SupportLevel?(SupportLevel.Transient); } else if (exception is MailboxInTransitException) { sendWatsonReport = false; message = Strings.GetLocalizedString(-1739093686); messageId = new Strings.IDs?(-1739093686); supportLevel = new SupportLevel?(SupportLevel.Transient); } else if (exception is ResourceUnhealthyException) { sendWatsonReport = false; message = Strings.GetLocalizedString(198161982); messageId = new Strings.IDs?(198161982); OwaDiagnostics.LogEvent(ClientsEventLogConstants.Tuple_ErrorResourceUnhealthy, string.Empty, new object[] { text, exception.ToString() }); } else if (exception is ConnectionFailedPermanentException || exception is ServerNotFoundException) { message = string.Format(Strings.GetLocalizedString(-765910865), text); messageId = new Strings.IDs?(-765910865); messageParameter = text; supportLevel = new SupportLevel?(SupportLevel.EscalateToSupport); } else if (exception is ConnectionFailedTransientException || exception is MailboxOfflineException) { if (exception.InnerException is MapiExceptionLogonFailed && mailboxContext.IsExplicitLogon) { message = Strings.GetLocalizedString(882888134); messageId = new Strings.IDs?(882888134); supportLevel = new SupportLevel?(SupportLevel.TenantAdmin); } else { message = Strings.GetLocalizedString(198161982); messageId = new Strings.IDs?(198161982); supportLevel = new SupportLevel?(SupportLevel.Transient); } } else if (exception is SendAsDeniedException) { message = Strings.GetLocalizedString(2059222100); messageId = new Strings.IDs?(2059222100); supportLevel = new SupportLevel?(SupportLevel.TenantAdmin); } else if (exception is ADTransientException) { message = Strings.GetLocalizedString(634294555); messageId = new Strings.IDs?(634294555); supportLevel = new SupportLevel?(SupportLevel.Transient); } else if (exception is ADOperationException) { message = Strings.GetLocalizedString(-256207770); messageId = new Strings.IDs?(-256207770); supportLevel = new SupportLevel?(SupportLevel.Unknown); } else if (exception is DataValidationException) { message = Strings.GetLocalizedString(-256207770); messageId = new Strings.IDs?(-256207770); supportLevel = new SupportLevel?(SupportLevel.EscalateToSupport); } else if (exception is SaveConflictException || exception is OwaSaveConflictException) { message = Strings.GetLocalizedString(-482397486); messageId = new Strings.IDs?(-482397486); } else if (exception is FolderSaveException) { message = Strings.GetLocalizedString(1487149567); messageId = new Strings.IDs?(1487149567); } else if (exception is ObjectValidationException) { message = Strings.GetLocalizedString(-1670564952); messageId = new Strings.IDs?(-1670564952); } else if (exception is CorruptDataException) { message = Strings.GetLocalizedString(-1670564952); messageId = new Strings.IDs?(-1670564952); } else if (exception is Microsoft.Exchange.Data.Storage.QuotaExceededException || exception is MessageTooBigException) { message = Strings.GetLocalizedString(-640701623); messageId = new Strings.IDs?(-640701623); } else if (exception is SubmissionQuotaExceededException) { message = Strings.GetLocalizedString(178029729); messageId = new Strings.IDs?(178029729); } else if (exception is MessageSubmissionExceededException) { message = Strings.GetLocalizedString(-1381793955); messageId = new Strings.IDs?(-1381793955); } else if (exception is AttachmentExceededException) { message = Strings.GetLocalizedString(-2137146650); messageId = new Strings.IDs?(-2137146650); } else if (exception is ResourcesException || exception is NoMoreConnectionsException) { message = Strings.GetLocalizedString(-639453714); messageId = new Strings.IDs?(-639453714); supportLevel = new SupportLevel?(SupportLevel.EscalateToSupport); } else if (exception is AccountDisabledException) { message = Strings.GetLocalizedString(531497785); messageId = new Strings.IDs?(531497785); supportLevel = new SupportLevel?(SupportLevel.TenantAdmin); } else if (exception is AccessDeniedException) { message = Strings.GetLocalizedString(995407892); messageId = new Strings.IDs?(995407892); AccessDeniedException ex2 = (AccessDeniedException)exception; if (ex2.InnerException != null) { Exception innerException = ex2.InnerException; if (innerException is MapiExceptionPasswordChangeRequired || innerException is MapiExceptionPasswordExpired) { message = Strings.GetLocalizedString(540943741); messageId = new Strings.IDs?(540943741); } } supportLevel = new SupportLevel?(SupportLevel.TenantAdmin); } else if (exception is InvalidLicenseException) { message = string.Format(Strings.GetLocalizedString(468041898), requestContext.UserContext.MailboxIdentity.SafeGetRenderableName()); messageId = new Strings.IDs?(468041898); messageParameter = requestContext.UserContext.MailboxIdentity.SafeGetRenderableName(); sendWatsonReport = false; supportLevel = new SupportLevel?(SupportLevel.TenantAdmin); } else if (exception is TenantAccessBlockedException) { message = Strings.GetLocalizedString(1045420842); messageId = new Strings.IDs?(1045420842); sendWatsonReport = false; supportLevel = new SupportLevel?(SupportLevel.EscalateToSupport); } else if (exception is PropertyErrorException) { message = Strings.GetLocalizedString(641346049); messageId = new Strings.IDs?(641346049); } else if (exception is OwaInvalidOperationException) { message = Strings.GetLocalizedString(641346049); messageId = new Strings.IDs?(641346049); } else if (exception is VirusDetectedException) { message = Strings.GetLocalizedString(-589723291); messageId = new Strings.IDs?(-589723291); } else if (exception is VirusScanInProgressException) { message = Strings.GetLocalizedString(-1019777596); messageId = new Strings.IDs?(-1019777596); } else if (exception is VirusMessageDeletedException) { message = Strings.GetLocalizedString(1164605313); messageId = new Strings.IDs?(1164605313); } else if (exception is OwaExplicitLogonException) { message = Strings.GetLocalizedString(882888134); messageId = new Strings.IDs?(882888134); sendWatsonReport = false; supportLevel = new SupportLevel?(SupportLevel.TenantAdmin); } else if (exception is NoReplicaException) { message = Strings.GetLocalizedString(1179266056); messageId = new Strings.IDs?(1179266056); } else if (exception is TooManyObjectsOpenedException) { message = Strings.GetLocalizedString(-1763248954); messageId = new Strings.IDs?(-1763248954); supportLevel = new SupportLevel?(SupportLevel.User); } else if (exception is OwaUserHasNoMailboxAndNoLicenseAssignedException) { message = Strings.GetLocalizedString(115127791); messageId = new Strings.IDs?(115127791); supportLevel = new SupportLevel?(SupportLevel.TenantAdmin); } else if (exception is UserHasNoMailboxException) { message = Strings.GetLocalizedString(-765910865); messageId = new Strings.IDs?(-765910865); messageParameter = exception.Data["PrimarySmtpAddress"].ToString(); supportLevel = new SupportLevel?(SupportLevel.TenantAdmin); } else if (exception is StorageTransientException) { message = Strings.GetLocalizedString(-238819799); messageId = new Strings.IDs?(-238819799); if (exception.InnerException is MapiExceptionRpcServerTooBusy) { sendWatsonReport = false; OwaDiagnostics.LogEvent(ClientsEventLogConstants.Tuple_ErrorMailboxServerTooBusy, string.Empty, new object[] { text, exception.ToString() }); } supportLevel = new SupportLevel?(SupportLevel.Transient); } else if (exception is RulesTooBigException) { message = Strings.GetLocalizedString(-791981113); messageId = new Strings.IDs?(-791981113); } else if (exception is DuplicateActionException) { message = Strings.GetLocalizedString(-555068615); messageId = new Strings.IDs?(-555068615); } else if (exception is ConversionFailedException && ((ConversionFailedException)exception).ConversionFailureReason == ConversionFailureReason.CorruptContent) { message = Strings.GetLocalizedString(-1670564952); messageId = new Strings.IDs?(-1670564952); } else if (exception is IOException && ErrorHandlerUtilities.IsDiskFullException(exception)) { sendWatsonReport = false; message = Strings.GetLocalizedString(-1729839551); messageId = new Strings.IDs?(-1729839551); supportLevel = new SupportLevel?(SupportLevel.EscalateToSupport); } else if (exception is StoragePermanentException) { message = Strings.GetLocalizedString(861904327); messageId = new Strings.IDs?(861904327); if (exception.InnerException is MapiPermanentException) { DiagnosticContext diagCtx = ((MapiPermanentException)exception.InnerException).DiagCtx; if (diagCtx != null) { lids = diagCtx.ToCompactString(); } } supportLevel = new SupportLevel?(SupportLevel.EscalateToSupport); } else if (exception is TransientException) { message = Strings.GetLocalizedString(-1729839551); messageId = new Strings.IDs?(-1729839551); supportLevel = new SupportLevel?(SupportLevel.Transient); if (exception.InnerException is MapiRetryableException) { DiagnosticContext diagCtx2 = ((MapiRetryableException)exception.InnerException).DiagCtx; if (diagCtx2 != null) { lids = diagCtx2.ToCompactString(); } } } else if (exception is HttpException) { HttpException ex3 = (HttpException)exception; message = string.Format(Strings.GetLocalizedString(1331629462), ex3.GetHttpCode()); messageId = new Strings.IDs?(1331629462); messageParameter = ex3.GetHttpCode().ToString(); } else if (exception is OverBudgetException) { sendWatsonReport = false; message = Strings.GetLocalizedString(1856724252); messageId = new Strings.IDs?(1856724252); } else if (exception is COMException || exception.InnerException is COMException) { sendWatsonReport = !ErrorHandlerUtilities.ShouldIgnoreException((exception is COMException) ? exception : exception.InnerException); message = Strings.GetLocalizedString(641346049); messageId = new Strings.IDs?(641346049); supportLevel = new SupportLevel?(SupportLevel.EscalateToSupport); } else if (exception is ThreadAbortException) { sendWatsonReport = false; message = Strings.GetLocalizedString(641346049); messageId = new Strings.IDs?(641346049); } else if (exception is FaultException || exception is InvalidSerializedAccessTokenException) { sendWatsonReport = false; message = exception.Message; } else if (exception is NonExistentMailboxException) { sendWatsonReport = false; message = exception.Message; supportLevel = new SupportLevel?(SupportLevel.TenantAdmin); } else if (exception is SlabManifestException || exception is FlightConfigurationException) { sendWatsonReport = false; message = Strings.GetLocalizedString(2099558169); messageId = new Strings.IDs?(2099558169); } else { sendWatsonReport = true; message = Strings.GetLocalizedString(641346049); messageId = new Strings.IDs?(641346049); } string empty = string.Empty; Strings.IDs?ds = null; bool siteMailbox = false; bool flag = ErrorHandlerUtilities.RemedyExceptionHandlingError(exception, requestContext, out empty, out ds, out siteMailbox); if (flag) { message = empty; messageId = ds; } string groupMailboxDestination = ErrorHandlerUtilities.GetGroupMailboxDestination(exception, requestContext); return(new ErrorInformation { Exception = exception, Message = message, MessageId = messageId, MessageParameter = messageParameter, SendWatsonReport = sendWatsonReport, SharePointApp = flag, SiteMailbox = siteMailbox, GroupMailboxDestination = groupMailboxDestination, Lids = lids, SupportLevel = supportLevel }); }
private ClientException ParseError(IRestResponse response) { if (response == null) { return new ConnectionException(); } if (HttpStatusCode.Redirect.Equals(response.StatusCode) || HttpStatusCode.TemporaryRedirect.Equals(response.StatusCode) || HttpStatusCode.MovedPermanently.Equals(response.StatusCode)) { return new RedirectionException(); } if (string.IsNullOrWhiteSpace(response.Content)) { if (HttpStatusCode.Forbidden.Equals(response.StatusCode) || HttpStatusCode.NotFound.Equals(response.StatusCode) || HttpStatusCode.MethodNotAllowed.Equals(response.StatusCode) || HttpStatusCode.NotImplemented.Equals(response.StatusCode)) { ClientException e = null; ErrorResponse errorResponse = new ErrorResponse(); foreach (Parameter parameter in response.Headers) { if (parameter.Name.Equals("x-amz-id-2", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.XAmzID2 = parameter.Value.ToString(); } if (parameter.Name.Equals("x-amz-request-id", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.RequestID = parameter.Value.ToString(); } } errorResponse.Resource = response.Request.Resource; if (HttpStatusCode.NotFound.Equals(response.StatusCode)) { int pathLength = response.Request.Resource.Split('/').Count(); if (pathLength > 1) { errorResponse.Code = "NoSuchKey"; e = new ObjectNotFoundException(); } else if (pathLength == 1) { errorResponse.Code = "NoSuchBucket"; e = new BucketNotFoundException(); } else { e = new InternalClientException("404 without body resulted in path with less than two components"); } } else if (HttpStatusCode.Forbidden.Equals(response.StatusCode)) { errorResponse.Code = "Forbidden"; e = new AccessDeniedException(); } else if (HttpStatusCode.MethodNotAllowed.Equals(response.StatusCode)) { errorResponse.Code = "MethodNotAllowed"; e = new MethodNotAllowedException(); } else { errorResponse.Code = "MethodNotAllowed"; e = new MethodNotAllowedException(); } e.Response = errorResponse; return e; } throw new InternalClientException("Unsuccessful response from server without XML error: " + response.StatusCode); } var contentBytes = System.Text.Encoding.UTF8.GetBytes(response.Content); var stream = new MemoryStream(contentBytes); ErrorResponse errResponse = (ErrorResponse)(new XmlSerializer(typeof(ErrorResponse)).Deserialize(stream)); string code = errResponse.Code; ClientException clientException; if ("NoSuchBucket".Equals(code)) clientException = new BucketNotFoundException(); else if ("NoSuchKey".Equals(code)) clientException = new ObjectNotFoundException(); else if ("InvalidBucketName".Equals(code)) clientException = new InvalidKeyNameException(); else if ("InvalidObjectName".Equals(code)) clientException = new InvalidKeyNameException(); else if ("AccessDenied".Equals(code)) clientException = new AccessDeniedException(); else if ("InvalidAccessKeyId".Equals(code)) clientException = new AccessDeniedException(); else if ("BucketAlreadyExists".Equals(code)) clientException = new BucketExistsException(); else if ("ObjectAlreadyExists".Equals(code)) clientException = new ObjectExistsException(); else if ("InternalError".Equals(code)) clientException = new InternalServerException(); else if ("KeyTooLong".Equals(code)) clientException = new InvalidKeyNameException(); else if ("TooManyBuckets".Equals(code)) clientException = new MaxBucketsReachedException(); else if ("PermanentRedirect".Equals(code)) clientException = new RedirectionException(); else if ("MethodNotAllowed".Equals(code)) clientException = new ObjectExistsException(); else if ("BucketAlreadyOwnedByYou".Equals(code)) clientException = new BucketExistsException(); else clientException = new InternalClientException(errResponse.ToString()); clientException.Response = errResponse; clientException.XmlError = response.Content; return clientException; }
public void OnException(ExceptionContext filterContext) { if (filterContext.ExceptionHandled) { return; } var appException = new AppException(); var statusCode = HttpStatusCode.InternalServerError; if (filterContext.Exception is HttpException) { statusCode = (HttpStatusCode)(filterContext.Exception as HttpException).GetHttpCode(); switch (statusCode) { case HttpStatusCode.BadRequest: { appException = new AppException(filterContext.Exception.Message, "ER400", HttpStatusCode.BadRequest); break; } case HttpStatusCode.Unauthorized: { appException = new AuthenticationRequiredException(filterContext.Exception.Message); break; } case HttpStatusCode.Forbidden: { appException = new AccessDeniedException(filterContext.Exception.Message); break; } case HttpStatusCode.InternalServerError: { appException = new AppException(filterContext.Exception.Message); break; } case HttpStatusCode.NotFound: { appException = new EntityNotFoundException(filterContext.Exception.Message); break; } } } else { try { filterContext.Exception.Handle(); } catch (AppException ex) { appException = ex; } } filterContext.Exception = appException; statusCode = appException.HttpStatus; var result = CreateActionResult(filterContext, statusCode); filterContext.Result = result; // Prepare the response code. filterContext.ExceptionHandled = true; filterContext.HttpContext.Response.Clear(); filterContext.HttpContext.Response.StatusCode = (int)statusCode; filterContext.HttpContext.Response.TrySkipIisCustomErrors = true; }
private ClientException ParseError(IRestResponse response) { if (response == null) { return(new ConnectionException("Response is nil. Please report this issue https://github.com/minio/minio-dotnet/issues")); } if (HttpStatusCode.Redirect.Equals(response.StatusCode) || HttpStatusCode.TemporaryRedirect.Equals(response.StatusCode) || HttpStatusCode.MovedPermanently.Equals(response.StatusCode)) { return(new RedirectionException("Redirection detected. Please report this issue https://github.com/minio/minio-dotnet/issues")); } if (string.IsNullOrWhiteSpace(response.Content)) { if (HttpStatusCode.Forbidden.Equals(response.StatusCode) || HttpStatusCode.NotFound.Equals(response.StatusCode) || HttpStatusCode.MethodNotAllowed.Equals(response.StatusCode) || HttpStatusCode.NotImplemented.Equals(response.StatusCode)) { ClientException e = null; ErrorResponse errorResponse = new ErrorResponse(); foreach (Parameter parameter in response.Headers) { if (parameter.Name.Equals("x-amz-id-2", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.HostId = parameter.Value.ToString(); } if (parameter.Name.Equals("x-amz-request-id", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.RequestId = parameter.Value.ToString(); } if (parameter.Name.Equals("x-amz-bucket-region", StringComparison.CurrentCultureIgnoreCase)) { errorResponse.BucketRegion = parameter.Value.ToString(); } } errorResponse.Resource = response.Request.Resource; if (HttpStatusCode.NotFound.Equals(response.StatusCode)) { int pathLength = response.Request.Resource.Split('/').Count(); if (pathLength > 1) { errorResponse.Code = "NoSuchKey"; var objectName = response.Request.Resource.Split('/')[1]; e = new ObjectNotFoundException(objectName, "Not found."); } else if (pathLength == 1) { errorResponse.Code = "NoSuchBucket"; var bucketName = response.Request.Resource.Split('/')[0]; e = new BucketNotFoundException(bucketName, "Not found."); } else { e = new InternalClientException("404 without body resulted in path with less than two components"); } } else if (HttpStatusCode.Forbidden.Equals(response.StatusCode)) { errorResponse.Code = "Forbidden"; e = new AccessDeniedException("Access denied on the resource: " + response.Request.Resource); } e.Response = errorResponse; return(e); } throw new InternalClientException("Unsuccessful response from server without XML error: " + response.StatusCode); } var contentBytes = System.Text.Encoding.UTF8.GetBytes(response.Content); var stream = new MemoryStream(contentBytes); ErrorResponse errResponse = (ErrorResponse)(new XmlSerializer(typeof(ErrorResponse)).Deserialize(stream)); ClientException clientException = new ClientException(errResponse.Message); clientException.Response = errResponse; clientException.XmlError = response.Content; return(clientException); }
private void ChannelRegistration <T>(IBasicProperties basicProperties, string queue, string errorQueue, string exchange, string routingKey, ConsumerResolver <T> resolver) { var rabbitConsumer = new EventingBasicConsumer(channel); rabbitConsumer.Received += (model, ea) => { var serializer = RabbitMQWrapperConnection.DefaultAdapter; try { var message = serializer.DeserializeBytes <RabbitMQWrapperMessage <T> >(ea.Body); AbstractConsumer <T> consumer = null; try { consumer = resolver(message.EventID, message.Event, message.ContractVersion); if (message.Event == "") { consumer.Consume(message.EventID, message.Content, message.ContractVersion); } consumer.Consume(message.Event, message.Content, message.ContractVersion); } catch (Exception e) { Logger.Error("Consumer: " + consumer + " has unexpected error", e); channel.BasicNack(deliveryTag: ea.DeliveryTag, multiple: false, requeue: true); return; } try { channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); } catch (Exception e) { Logger.Error("Connection lost", e); throw e; } } catch (JsonException e) { var customError = new UnexpectedException(e); Logger.Error("Could not deserialize the object: " + ea.Body, customError); try { Logger.Warn("Creating error queue..."); this.EnsureRoute(errorQueue, exchange, routingKey); this.channel.BasicPublish(exchange: exchange, routingKey: routingKey, basicProperties: basicProperties, body: ea.Body); channel.BasicNack(deliveryTag: ea.DeliveryTag, multiple: false, requeue: false); } catch (Exception ex) { var custom = new UnexpectedException(ex); Logger.Fatal("Unexpected error occured while publishing items to error queue", custom); throw custom; } } catch (Exception e) { var custom = new UnexpectedException(e); Logger.Fatal("Unexpected error occured while consumer received a message", custom); throw custom; } }; try { channel.BasicConsume(queue: queue, noAck: false, consumer: rabbitConsumer, consumerTag: appKey); } catch (IOException e) { if (channel.IsOpen == false) { var custom = new ConnectionClosedException(e); Logger.Info("Trying to reconnect again... Queue:" + queue, custom); Thread.Sleep(200); channel.BasicConsume(queue: queue, noAck: false, consumer: rabbitConsumer, consumerTag: appKey); } else { var custom = new AccessDeniedException(e); Logger.Fatal("Access denied. Queue: " + queue, custom); throw custom; } } }
void OnError(AccessDeniedException e) { NavigationHelper.GoToResultPageAndClearTop(this); }