Table of Contents

Class DatabaseReplies

Namespace
FishMMO.ControlPanel.Controllers
Assembly
FishMMO-ControlPanel.dll

Turns a failed DatabaseResult into the reply the panel gives for it.

public static class DatabaseReplies
Inheritance
DatabaseReplies
Inherited Members

Remarks

A failed result is one of three different things, and the panel used to answer all three the same way — a 400 carrying ErrorMessage:

  • Not found. The row the request named does not exist. A 404, with the caller's own wording, because "no such account" is a sentence the page already knows how to say.
  • A refusal. The service said no: a value out of range, a ticket above the actor's tier, a stale version, a code that does not redeem. The message was written by the service to be read, and it is passed through as a 400 exactly as before.
  • A fault. The database failed: a dropped connection, a timeout, a statement that threw. Its message is built from the underlying exception (BaseService.MapFinalException) and can carry a host, a port or a column name, which is nobody's business in a browser — and a 400 told the browser the request was wrong, when trying it again was the right thing to do. A 503 with the caller's own wording, and the real message goes to the log, where it is useful.

A controller that treats a particular code specially (a 409 for a stale edit, a named collision) still does so before calling this. This is the answer for everything else.

Methods

Failure(ControllerBase, DatabaseResult, ILogger?, string, string?)

The reply for a failed result. See the remarks on this class.

public static IActionResult Failure(ControllerBase controller, DatabaseResult result, ILogger? log, string fault, string? notFound = null)

Parameters

controller ControllerBase

The controller answering.

result DatabaseResult

The failed result.

log ILogger

Where a fault's real message is written; null only when the caller has already logged it.

fault string

What the reader is told when the database failed. Also the fallback for a refusal with no message.

notFound string

What the reader is told when the row does not exist; the service's own message when null.

Returns

IActionResult

Failure<T>(ControllerBase, DatabaseResult<T>, ILogger?, string, string?)

The reply for a failed result. See the remarks on this class.

public static IActionResult Failure<T>(ControllerBase controller, DatabaseResult<T> result, ILogger? log, string fault, string? notFound = null)

Parameters

controller ControllerBase

The controller answering.

result DatabaseResult<T>

The failed result.

log ILogger

Where a fault's real message is written; null only when the caller has already logged it.

fault string

What the reader is told when the database failed. Also the fallback for a refusal with no message.

notFound string

What the reader is told when the row does not exist; the service's own message when null.

Returns

IActionResult

Type Parameters

T

IsFault(string?)

Whether a failure is the database failing, rather than an answer about the request.

public static bool IsFault(string? errorCode)

Parameters

errorCode string

Returns

bool

IsNotFound(string?)

Whether a failure means the row asked for does not exist.

public static bool IsNotFound(string? errorCode)

Parameters

errorCode string

Returns

bool

IsRefusal(string?)

Whether a failure is the service refusing, rather than the database failing.

public static bool IsRefusal(string? errorCode)

Parameters

errorCode string

Returns

bool

Remarks

Every code here carries a message that was either written by a service for its reader or is one of the fixed, safe sentences the base service maps a constraint violation to. INVALID_ARGUMENT and INVALID_OPERATION are deliberately absent: they are built from framework exception text, including EF's inner exceptions.

Outcome(DatabaseResult)

The audit row's outcome for a failed result: the service's sentence for a refusal, and the code as well for a fault, so the row says which kind of failure it was.

public static string? Outcome(DatabaseResult result)

Parameters

result DatabaseResult

Returns

string

Outcome<T>(DatabaseResult<T>)

The audit row's outcome for a failed result: the service's sentence for a refusal, and the code as well for a fault, so the row says which kind of failure it was.

public static string? Outcome<T>(DatabaseResult<T> result)

Parameters

result DatabaseResult<T>

Returns

string

Type Parameters

T