aboutsummaryrefslogtreecommitdiff
path: root/docker/crupest-api/CrupestApi/CrupestApi.Commons/Error.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-12-02 11:04:34 +0800
committercrupest <crupest@outlook.com>2022-12-02 13:35:35 +0800
commit300842e81a99db6da103f146d33eb47f43efc683 (patch)
tree2f80b57945408b8af83556a4efe5a92dea98e025 /docker/crupest-api/CrupestApi/CrupestApi.Commons/Error.cs
parent49ada0b891a93cf0f1c0dfc2cb5b1d103019b7c8 (diff)
downloadcrupest-300842e81a99db6da103f146d33eb47f43efc683.tar.gz
crupest-300842e81a99db6da103f146d33eb47f43efc683.tar.bz2
crupest-300842e81a99db6da103f146d33eb47f43efc683.zip
...
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Error.cs')
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons/Error.cs19
1 files changed, 19 insertions, 0 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Error.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Error.cs
new file mode 100644
index 0000000..b298f7a
--- /dev/null
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Error.cs
@@ -0,0 +1,19 @@
+namespace CrupestApi.Commons;
+
+public class ErrorBody
+{
+ public ErrorBody(string message)
+ {
+ Message = message;
+ }
+
+ public string Message { get; set; }
+}
+
+public static class CrupestApiErrorExtensions
+{
+ public static async Task WriteErrorMessageAsync(this HttpResponse response, string message, int statusCode = 400, HttpResponseAction? beforeWriteBody = null, CancellationToken cancellationToken = default)
+ {
+ await response.WriteJsonAsync(new ErrorBody(message), statusCode: statusCode, beforeWriteBody, cancellationToken);
+ }
+}