summary refs log tree commit diff
path: root/extra/admin-api/Models/Spacebar.Models.Api/SpacebarApiError.cs
blob: 03bf9264c891ff44b62afa0a91afe56408577cf8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System.Text.Json.Nodes;

namespace Spacebar.Models.Api;

public class SpacebarApiException : Exception {
    public int Code { get; set; }
    public string? Request { get; set; } // Spacebar extension
    // public Dictionary<string, FieldErrorList> Errors { get; set; }
    public JsonObject? Errors { get; set; }

    public class FieldErrorList {
        // public 
    }

    public SpacebarApiException(string? message) : base(message) {
        
    }

    // TODO: abstract out to HTTP layer
    public static SpacebarApiException FromJson(JsonObject resp) {
        var ex = new SpacebarApiException(resp["message"]!.GetValue<string>()) {
            Code = resp["code"]!.GetValue<int>(),
            Request = resp["request"]?.GetValue<string>(),
            Errors = resp["errors"]?.AsObject()
        };

        return ex;
    }
}