Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<RepositoryUrl>https://github.com/managedcode/Communication</RepositoryUrl>
<PackageProjectUrl>https://github.com/managedcode/Communication</PackageProjectUrl>
<Product>Managed Code - Communication</Product>
<Version>9.6.0</Version>
<PackageVersion>9.6.0</PackageVersion>
<Version>9.6.1</Version>
<PackageVersion>9.6.1</PackageVersion>

</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public static CollectionResult<T> Fail(string title)
var problem = Problem.Create(title, title, (int)HttpStatusCode.InternalServerError);
return Create(false, default, 0, 0, 0, problem);
}

public static CollectionResult<T> Fail(string title, string detail)
{
var problem = Problem.Create(title, detail);
return Create(false, default, 0, 0, 0, problem);
}

public static CollectionResult<T> Fail(string title, string detail, HttpStatusCode status)
{
var problem = Problem.Create(title, detail, (int)status);
Expand All @@ -50,7 +50,7 @@ public static CollectionResult<T> Fail(Exception exception)
{
return new CollectionResult<T>(false, default, 0, 0, 0, Problem.Create(exception, (int)HttpStatusCode.InternalServerError));
}

public static CollectionResult<T> Fail(Exception exception, HttpStatusCode status)
{
return new CollectionResult<T>(false, default, 0, 0, 0, Problem.Create(exception, (int)status));
Expand All @@ -61,6 +61,26 @@ public static CollectionResult<T> FailValidation(params (string field, string me
return new CollectionResult<T>(false, default, 0, 0, 0, Problem.Validation(errors));
}

public static CollectionResult<T> FailBadRequest()
{
var problem = Problem.Create(
ProblemConstants.Titles.BadRequest,
ProblemConstants.Messages.BadRequest,
(int)HttpStatusCode.BadRequest);

return Create(false, default, 0, 0, 0, problem);
}

public static CollectionResult<T> FailBadRequest(string detail)
{
var problem = Problem.Create(
ProblemConstants.Titles.BadRequest,
detail,
(int)HttpStatusCode.BadRequest);

return Create(false, default, 0, 0, 0, problem);
}

public static CollectionResult<T> FailUnauthorized()
{
var problem = Problem.Create(
Expand All @@ -70,7 +90,7 @@ public static CollectionResult<T> FailUnauthorized()

return Create(false, default, 0, 0, 0, problem);
}

public static CollectionResult<T> FailUnauthorized(string detail)
{
var problem = Problem.Create(
Expand All @@ -90,7 +110,7 @@ public static CollectionResult<T> FailForbidden()

return Create(false, default, 0, 0, 0, problem);
}

public static CollectionResult<T> FailForbidden(string detail)
{
var problem = Problem.Create(
Expand All @@ -110,7 +130,7 @@ public static CollectionResult<T> FailNotFound()

return Create(false, default, 0, 0, 0, problem);
}

public static CollectionResult<T> FailNotFound(string detail)
{
var problem = Problem.Create(
Expand All @@ -125,7 +145,7 @@ public static CollectionResult<T> Fail<TEnum>(TEnum errorCode) where TEnum : Enu
{
return new CollectionResult<T>(false, default, 0, 0, 0, Problem.Create(errorCode));
}

public static CollectionResult<T> Fail<TEnum>(TEnum errorCode, string detail) where TEnum : Enum
{
return new CollectionResult<T>(false, default, 0, 0, 0, Problem.Create(errorCode, detail));
Expand All @@ -135,9 +155,9 @@ public static CollectionResult<T> Fail<TEnum>(TEnum errorCode, HttpStatusCode st
{
return new CollectionResult<T>(false, default, 0, 0, 0, Problem.Create(errorCode, errorCode.ToString(), (int)status));
}

public static CollectionResult<T> Fail<TEnum>(TEnum errorCode, string detail, HttpStatusCode status) where TEnum : Enum
{
return new CollectionResult<T>(false, default, 0, 0, 0, Problem.Create(errorCode, detail, (int)status));
}
}
}
7 changes: 4 additions & 3 deletions ManagedCode.Communication/Constants/ProblemConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static class Titles
/// </summary>
public static class Messages
{
public const string BadRequest = "The request could not be understood by the server due to malformed syntax.";
public const string UnauthorizedAccess = "Authentication is required to access this resource.";
public const string ForbiddenAccess = "You do not have permission to access this resource.";
public const string ResourceNotFound = "The requested resource was not found.";
Expand All @@ -44,7 +45,7 @@ public static class Types
{
public const string AboutBlank = "about:blank";
public const string ValidationFailed = "https://tools.ietf.org/html/rfc7231#section-6.5.1";

public static string HttpStatus(int statusCode) => $"https://httpstatuses.io/{statusCode}";
}

Expand Down Expand Up @@ -83,7 +84,7 @@ public static class ExtensionKeys
/// </summary>
public const string OriginalExceptionType = "originalExceptionType";
}

/// <summary>
/// Field names for validation errors.
/// </summary>
Expand All @@ -94,4 +95,4 @@ public static class ValidationFields
/// </summary>
public const string General = "_general";
}
}
}
46 changes: 36 additions & 10 deletions ManagedCode.Communication/Result/Result.Fail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static Result Fail(string title)
var problem = Problem.Create(title, title, HttpStatusCode.InternalServerError);
return Create(false, problem);
}

/// <summary>
/// Creates a failed result with a title and detail.
/// </summary>
Expand All @@ -40,7 +40,7 @@ public static Result Fail(string title, string detail)
var problem = Problem.Create(title, detail, HttpStatusCode.InternalServerError);
return Create(false, problem);
}

/// <summary>
/// Creates a failed result with a title, detail and status.
/// </summary>
Expand All @@ -57,7 +57,7 @@ public static Result Fail(Exception exception)
{
return Create(false, Problem.Create(exception, (int)HttpStatusCode.InternalServerError));
}

/// <summary>
/// Creates a failed result from an exception with specific status.
/// </summary>
Expand All @@ -74,6 +74,32 @@ public static Result FailValidation(params (string field, string message)[] erro
return new Result(false, Problem.Validation(errors));
}

/// <summary>
/// Creates a failed result for bad request.
/// </summary>
public static Result FailBadRequest()
{
var problem = Problem.Create(
ProblemConstants.Titles.BadRequest,
ProblemConstants.Messages.BadRequest,
(int)HttpStatusCode.BadRequest);

return Create(false, problem);
}

/// <summary>
/// Creates a failed result for bad request with custom detail.
/// </summary>
public static Result FailBadRequest(string detail)
{
var problem = Problem.Create(
ProblemConstants.Titles.BadRequest,
detail,
(int)HttpStatusCode.BadRequest);

return Create(false, problem);
}

/// <summary>
/// Creates a failed result for unauthorized access.
/// </summary>
Expand All @@ -86,7 +112,7 @@ public static Result FailUnauthorized()

return Create(false, problem);
}

/// <summary>
/// Creates a failed result for unauthorized access with custom detail.
/// </summary>
Expand All @@ -112,7 +138,7 @@ public static Result FailForbidden()

return Create(false, problem);
}

/// <summary>
/// Creates a failed result for forbidden access with custom detail.
/// </summary>
Expand All @@ -138,7 +164,7 @@ public static Result FailNotFound()

return Create(false, problem);
}

/// <summary>
/// Creates a failed result for not found with custom detail.
/// </summary>
Expand All @@ -159,7 +185,7 @@ public static Result Fail<TEnum>(TEnum errorCode) where TEnum : Enum
{
return Create(false, Problem.Create(errorCode));
}

/// <summary>
/// Creates a failed result from a custom error enum with detail.
/// </summary>
Expand All @@ -175,12 +201,12 @@ public static Result Fail<TEnum>(TEnum errorCode, HttpStatusCode status) where T
{
return Create(false, Problem.Create(errorCode, errorCode.ToString(), (int)status));
}

/// <summary>
/// Creates a failed result from a custom error enum with detail and specific HTTP status.
/// </summary>і
/// </summary>і
public static Result Fail<TEnum>(TEnum errorCode, string detail, HttpStatusCode status) where TEnum : Enum
{
return Create(false, Problem.Create(errorCode, detail, (int)status));
}
}
}
44 changes: 35 additions & 9 deletions ManagedCode.Communication/ResultT/ResultT.Fail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static Result<T> Fail(string title)
var problem = Problem.Create(title, title, (int)HttpStatusCode.InternalServerError);
return Create(false, default, problem);
}

/// <summary>
/// Creates a failed result with a title and detail.
/// </summary>
Expand All @@ -52,7 +52,7 @@ public static Result<T> Fail(string title, string detail)
var problem = Problem.Create(title, detail);
return Create(false, default, problem);
}

/// <summary>
/// Creates a failed result with a title, detail and status.
/// </summary>
Expand All @@ -69,7 +69,7 @@ public static Result<T> Fail(Exception exception)
{
return new Result<T>(false, default, Problem.Create(exception, (int)HttpStatusCode.InternalServerError));
}

/// <summary>
/// Creates a failed result from an exception with status.
/// </summary>
Expand All @@ -86,6 +86,32 @@ public static Result<T> FailValidation(params (string field, string message)[] e
return new Result<T>(false, default, Problem.Validation(errors));
}

/// <summary>
/// Creates a failed result for bad request.
/// </summary>
public static Result<T> FailBadRequest()
{
var problem = Problem.Create(
ProblemConstants.Titles.BadRequest,
ProblemConstants.Messages.BadRequest,
(int)HttpStatusCode.BadRequest);

return Create(false, default, problem);
}

/// <summary>
/// Creates a failed result for bad request with custom detail.
/// </summary>
public static Result<T> FailBadRequest(string detail)
{
var problem = Problem.Create(
ProblemConstants.Titles.BadRequest,
detail,
(int)HttpStatusCode.BadRequest);

return Create(false, default, problem);
}

/// <summary>
/// Creates a failed result for unauthorized access.
/// </summary>
Expand All @@ -98,7 +124,7 @@ public static Result<T> FailUnauthorized()

return Create(false, default, problem);
}

/// <summary>
/// Creates a failed result for unauthorized access with custom detail.
/// </summary>
Expand All @@ -124,7 +150,7 @@ public static Result<T> FailForbidden()

return Create(false, default, problem);
}

/// <summary>
/// Creates a failed result for forbidden access with custom detail.
/// </summary>
Expand All @@ -150,7 +176,7 @@ public static Result<T> FailNotFound()

return Create(false, default, problem);
}

/// <summary>
/// Creates a failed result for not found with custom detail.
/// </summary>
Expand All @@ -171,7 +197,7 @@ public static Result<T> Fail<TEnum>(TEnum errorCode) where TEnum : Enum
{
return new Result<T>(false, default, Problem.Create(errorCode));
}

/// <summary>
/// Creates a failed result from a custom error enum with detail.
/// </summary>
Expand All @@ -187,12 +213,12 @@ public static Result<T> Fail<TEnum>(TEnum errorCode, HttpStatusCode status) wher
{
return new Result<T>(false, default, Problem.Create(errorCode, errorCode.ToString(), (int)status));
}

/// <summary>
/// Creates a failed result from a custom error enum with detail and specific HTTP status.
/// </summary>
public static Result<T> Fail<TEnum>(TEnum errorCode, string detail, HttpStatusCode status) where TEnum : Enum
{
return new Result<T>(false, default, Problem.Create(errorCode, detail, (int)status));
}
}
}
Loading