Activities of "berkansasmaz"

In the meantime, I'd like to share some information for more elegant error handling.

In general, we do not want users to go to the Error page, so I generally prefer to use a method like the one below.

I am creating a method inside MyProjectNamePageModel (class inherited from AbpPageModel) as below.

        protected void ShowAlert(Exception exception)
        {
            Logger.LogException(exception);
            var errorInfoConverter = LazyServiceProvider.LazyGetRequiredService<IExceptionToErrorInfoConverter>();
            var errorInfo = errorInfoConverter.Convert(exception, false);
            Alerts.Danger(errorInfo.Message);
        }

The errorInfoConverter.Convert method here makes the message of a BusinessException(or others Abp's exceptions) thrown in the domain appear in the UI, if you don't need it, you can remove it.

Then, with a code like the following, we ensure that the user stays on this page instead of a separate page when the error is thrown.

        public async Task<IActionResult> OnPostAsync()
        {
            try
            {
                ValidateModel();

               //Your CODE

                return RedirectToPage("/");
            }
            catch (Exception exception)
            {
                ShowAlert(exception);
               
                return Page();
            }
        }

For more information you can check here.

You probably already know, but I still wanted to share this information in case it helps users who have the same problem, I hope it helps 👋

Hi,

We don't need to write a custom exception handling middleware for this, but instead we need to override ABP's DefaultExceptionToErrorInfoConverter.

Based on what I understand from your needs, I created a folder named ExceptionHandling in MyProjectName.Domain and put the following code in it.

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IExceptionToErrorInfoConverter))]
    public class MyExceptionToErrorInfoConverter : DefaultExceptionToErrorInfoConverter, IExceptionToErrorInfoConverter
    {
        public MyExceptionToErrorInfoConverter(IOptions<AbpExceptionLocalizationOptions> localizationOptions, IStringLocalizerFactory stringLocalizerFactory, IStringLocalizer<AbpExceptionHandlingResource> stringLocalizer, IServiceProvider serviceProvider) : base(localizationOptions, stringLocalizerFactory, stringLocalizer, serviceProvider)
        {
        }
        
        protected override RemoteServiceErrorInfo CreateErrorInfoWithoutCode(Exception exception, bool includeSensitiveDetails)
        {
            if (includeSensitiveDetails)
            {
                return CreateDetailedErrorInfoFromException(exception);
            }

            exception = TryToGetActualException(exception);

            if (exception is AbpRemoteCallException remoteCallException)
            {
                return remoteCallException.Error;
            }

            if (exception is AbpDbConcurrencyException)
            {
                return new RemoteServiceErrorInfo(L["AbpDbConcurrencyErrorMessage"]);
            }

            if (exception is EntityNotFoundException)
            {
                return CreateEntityNotFoundError(exception as EntityNotFoundException);
            }

            var errorInfo = new RemoteServiceErrorInfo();

            if (exception is IUserFriendlyException or ArgumentNullException) // Here ArgumentNullException
            {
                errorInfo.Message = exception.Message;
                errorInfo.Details = (exception as IHasErrorDetails)?.Details;
            }

            if (exception is IHasValidationErrors)
            {
                if (errorInfo.Message.IsNullOrEmpty())
                {
                    errorInfo.Message = L["ValidationErrorMessage"];
                }

                if (errorInfo.Details.IsNullOrEmpty())
                {
                    errorInfo.Details = GetValidationErrorNarrative(exception as IHasValidationErrors);
                }

                errorInfo.ValidationErrors = GetValidationErrorInfos(exception as IHasValidationErrors);
            }

            TryToLocalizeExceptionMessage(exception, errorInfo);

            if (errorInfo.Message.IsNullOrEmpty())
            {
                errorInfo.Message = L["InternalServerErrorMessage"];
            }

            errorInfo.Data = exception.Data;

            return errorInfo;
        }
    }

The only difference from the default CreateErrorInfoWithoutCode method is the line with the comment line.

Now you can see ArgumentException thrown in domain. Of course, you can customize how you want to see it according to your needs.

I hope my answer helps in customizing to your needs.

Hello, as a result of my tests, I encountered the same problem, it's a bug.

As a workaround, I copied the appsettings.json file inside the MyProjectName.Blazor project into the MyProjectName.Blazor/wwwroot folder.

I'm creating an internal issue related to the topic.

Hi, can't you download when you request via swagger?

Please give some more code details.

Hi 👋,

This question doesn't seem to be about ABP, but I still want to share with you a few tips we use in our own kitchen ✌️

For preview, you can convert the PDF file to JPG and show it to the user.

For printing we use the PdfSharpCore package. You can check this video about using the package. Basically what is done is to place the data according to the coordinates on PDF.

I hope this information will help you and you can do what you want more easily 😊

Unfortunately, I would really like to help on this issue, but I have no information. I don't think the problem is related to ABP

You are trying to view the log records from Azure, but maybe its configuration is missing.

If you think the problem is really related to ABP, you can send your application or minimal, reproducible example to berkan.sasmaz@volosoft.com

Hi,

As I understand it, our first problem has been solved. 👇👇

I am attempting to publish the application onto Azure. But sadly the services are not starting. Attached is the stdout.

Because the error in the first log record does not appear in the log anymore.

Coming to our current problem, I don't think it's related to ABP. There is no information about ABP in the last log you sent.

In this case, unfortunately I can't be of any further help 😔

Maybe you can consider lowering the log level of the application, then there may be information about ABP.

Is the log of the published application you run locally empty? If it is not empty, could you share the relevant log?

This is possible, if you delete the code in the picture in my previous answer from the MyProjectName.IdentityServer(and other projects) project, you can publish and run it with the Development environment variable.

But, I cannot recommend publishing the application in the Development environment because; In general,it is desirable that the Development and Production environment be as similar as possible. However, there are a few fundamental differences. For example, while the UseDeveloperExceptionPage middleware is requested to work only with the Development environment variable, the UseErrorPage middleware is requested to run in the Production environment. Considering such situations, even if what you want is not recommended, it does not mean that you cannot do it.

Can you share the relevant logs in MyProjectName.HttpApi.Host and MyProjectName.Web? And I would be very happy if you could share the details of the request sent over the network.

Showing 281 to 290 of 332 entries
Made with ❤️ on ABP v9.0.0-preview Updated on September 20, 2024, 05:21