From e44fbf31892b93ab687c8740311ba0efcc07a369 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Fri, 30 Dec 2022 14:23:56 +0200 Subject: [PATCH] Added more exception types for handling various error codes --- source/libpb.d | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/source/libpb.d b/source/libpb.d index f2fd2a3..6bc31a1 100644 --- a/source/libpb.d +++ b/source/libpb.d @@ -24,6 +24,30 @@ public final class RecordNotFoundException : PBException } } +public final class NotAuthorized : PBException +{ + public const string offendingTable; + public const string offendingId; + this(string table, string id) + { + this.offendingTable = table; + this.offendingId = id; + } +} + +public final class ValidationRequired : PBException +{ + public const string offendingTable; + public const string offendingId; + this(string table, string id) + { + this.offendingTable = table; + this.offendingId = id; + } +} + + + public final class NetworkException : PBException { this() @@ -119,6 +143,22 @@ public class PocketBase return recordOut; } + catch(HTTPStatusException e) + { + if(e.status == 403) + { + throw new NotAuthorized(table, item.id); + } + else if(e.status == 400) + { + throw new ValidationRequired(table, item.id); + } + else + { + // TODO: Fix this + throw new NetworkException(); + } + } catch(CurlException e) { throw new NetworkException(); @@ -210,6 +250,14 @@ public class PocketBase { throw new RecordNotFoundException(table, item.id); } + else if(e.status == 403) + { + throw new NotAuthorized(table, item.id); + } + else if(e.status == 400) + { + throw new ValidationRequired(table, item.id); + } else { // TODO: Fix this