Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ProblemInstanceException #172

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Altinn.Authorization.ProblemDetails;

/// <summary>
/// An exception that represents a <see cref="ProblemInstance"/>.
/// </summary>
public class ProblemInstanceException
: InvalidOperationException
{
/// <summary>
/// Initializes a new instance of the <see cref="ProblemInstanceException"/> class.
/// </summary>
/// <param name="problemInstance">The <see cref="ProblemInstance"/>.</param>
public ProblemInstanceException(ProblemInstance problemInstance)
: base(problemInstance.Detail)
{
ProblemInstance = problemInstance;
}

/// <summary>
/// Gets the <see cref="ProblemInstance"/>.
/// </summary>
public ProblemInstance ProblemInstance { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@
get => _problem is null;
}

/// <summary>
/// Ensures that the operation succeeded.
/// </summary>
/// <exception cref="ProblemInstanceException">Thrown if the operation failed.</exception>
[MemberNotNull(nameof(Value))]
public void EnsureSuccess()
{
if (!IsSuccess)
{
throw new ProblemInstanceException(_problem!);
}
}

/// <summary>
/// Gets the problem instance if the operation failed, otherwise <see langword="null"/>.
/// </summary>
Expand Down Expand Up @@ -121,7 +134,7 @@
/// <inheritdoc/>
public override int GetHashCode()
=> _problem is not null ? _problem.GetHashCode()
: _result is not null ? _result.GetHashCode()

Check warning on line 137 in src/Altinn.Authorization.ProblemDetails/src/ProblemDetails.Abstractions/Result.cs

View workflow job for this annotation

GitHub Actions / Analyze

Extract this nested ternary operation into an independent statement. (https://rules.sonarsource.com/csharp/RSPEC-3358)
: 0;

/// <inheritdoc/>
Expand Down
Loading