Skip to content

Critical ErrorResult #140

@EnochMtzR

Description

@EnochMtzR

Specific Case:

The Issue:

Currently, there is no ResultStatus that may be mapped to the 500 error code since the Error ResultStatus maps (quite rightly, in my opinion) to a 422 Unprocessable error code.

However, I have the following specific case:

public async Task<ActionResult<Result>> RegisterTaxInfoForCurrentCustomer(ClaimsPrincipal user,
        NewCorporateTaxInfoRequest request)
    {
        try
        {
            var customer = await FindCustomerFromAuthenticatedUser(user);

            if (customer is null)
                return Result.NotFound("Customer not found");

            var taxAddress = GetTaxAddressFromCustomerById(customer, request.TaxAddressId);

            if (taxAddress is null)
                return Result.NotFound("Tax address not found");

            var taxInfo = request.ToCorporateTaxInfo(customer, taxAddress);

            customer.AddTaxInfo(taxInfo);
            await _customerRepository.UpdateAsync(customer);

            return Result.Success();
        }
        catch (UserIdCannotBeRetrieved exception)
        {
            Console.WriteLine(exception);
            return Result.Error("Authentication failed");
        }
        catch (InvalidTaxAddressId exception)
        {
            Console.WriteLine(exception);
            return exception.ToInvalidResult(nameof(request.TaxAddressId));
        }
        catch (InvalidTaxId exception)
        {
            Console.WriteLine(exception);
            return exception.ToInvalidResult(nameof(request.TaxId));
        }
    }

The UserIdCannotBeRetireved exception is thrown when the IDP did not set the sub claim. This, in my opinion, is a critical error and should return an InternalServerError (status 500) since this is not an issue with anything the user has done.

The Proposal:

A new CriticalError ResultStatus that maps to an InternalServerError (500) status code.

I have a pull request with my take on this issue: #141

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions