< Summary

Information
Class: Api.Utils.DomainException
Assembly: Api
File(s): /home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Utils/DomainErrors.cs
Line coverage
100%
Covered lines: 2
Uncovered lines: 0
Coverable lines: 2
Total lines: 33
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%

File(s)

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Utils/DomainErrors.cs

#LineLine coverage
 1// SPDX-FileCopyrightText: 2026 Alper Çelik <[email protected]>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5namespace Api.Utils;
 6
 7/// <summary>
 8/// An expected failure carrying the error code reported to the client. Throw it wherever the
 9/// failure is detected — input rules, business conflicts, rejected uploads — and
 10/// HotChocolate's mutation error middleware (see <c>[Error]</c>) reports it in the payload's
 11/// <c>errors</c> list. Unexpected failures stay exceptions and remain GraphQL errors.
 12/// </summary>
 113public sealed class DomainException(string code, string message) : Exception(message)
 14{
 115    public string Code { get; } = code;
 16}
 17
 18/// <summary>
 19/// The error shape reported in mutation payloads, paired with <see cref="DomainException"/>
 20/// through its <c>CreateErrorFrom</c> factory. Named <c>DomainError</c> because <c>Error</c>
 21/// is the interface HotChocolate adds to every error type.
 22/// </summary>
 23public sealed class DomainError
 24{
 25    private DomainError(string message, string code) => (Message, Code) = (message, code);
 26
 27    public string Message { get; }
 28
 29    public string Code { get; }
 30
 31    public static DomainError CreateErrorFrom(DomainException ex) =>
 32        new(ex.Message, ex.Code);
 33}

Methods/Properties

.ctor(string, string)