mirror of https://github.com/Hax-io/libpb
Added more exception types for handling various error codes
This commit is contained in:
parent
1027e5580f
commit
e44fbf3189
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue