RepositoryException Class
Assembly: CodeEffects.Rule.Repository.dll
Namespace: CodeEffects.Rule.Repository
Summary
The exception that the Rule Repository throws when it cannot complete a request, a source sync, or a reindex.
Syntax
public class RepositoryException : CodeEffects.Rule.Common.RuleException
You never create this exception. Context.GetResponse(..) and Context.GetRequestToken(..) throw it when a request fails, Context.SyncSources(..) when one or more source definitions fail, and Context.Reindex(..) when one or more source objects fail. The Message of the exception is safe to show to a user. The underlying failure, a database error included, is the InnerException. Log it on the server and never send it to the browser.
The repository has no logging of its own. Errors reach your application the way every other .NET error does, so the error handling and logging that your application already has see them. Warnings are not errors. A missing permission, a record that someone else has changed, and a failed validation are returned in the response and are never thrown. The one exception is a refusal for a missing permission, which RepositoryPermissionException reports so that you can log it.
A host that wants its users to see a friendly message with a control number, instead of a failed HTTP call, catches this exception around Context.GetResponse(..), logs it, and returns the ResponseJson property as the result of its endpoint. Catch RepositoryPermissionException first, because it derives from this class. When the failure of the database is the reason, ResponseJson carries a general message and the control number, never the text of the database error.
Any other exception that occurs while GetResponse(..) handles a request is wrapped in a RepositoryException, so the call throws this exception or RepositoryPermissionException and nothing else. SyncSources(..) and Reindex(..) throw a RuleException instead when you pass them a null argument.
Properties
ReindexResult
Type: CodeEffects.Rule.Repository.ReindexResult
Gets the full result of a reindex in which one or more source objects failed, including every source object that succeeded. It is null for every other failure. The InnerException of the exception is the error of the first source object that failed. The property is read-only.
ResponseJson
Type: System.String
Gets the response to send to the browser in place of the one that the request could not produce: the general message, the control number, and the notification type Error. It is null when the exception comes from Context.SyncSources(..) or Context.Reindex(..). The property is read-only.
SyncResult
Type: CodeEffects.Rule.Repository.SyncResult
Gets the full result of a source sync in which one or more source definitions failed, including every definition that succeeded. Every definition is processed, and one that fails does not stop the others, so this result tells you which ones failed and why. It is null for request failures. The property is read-only.
Inherited Properties
Example
using CodeEffects.Rule.Repository;
try
{
return Context.GetResponse(config, dbProvider, requestJson);
}
catch (RepositoryPermissionException ex)
{
logger.LogWarning("Refused {Action}: {Message}", ex.Action, ex.Message);
return ex.ResponseJson;
}
catch (RepositoryException ex)
{
// Log everything on the server; the browser gets the general message and the control number only.
logger.LogError(ex, "Request failed: {ControlNumber}", ex.ControlNumber);
return ex.ResponseJson;
}
Inheritance