-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from wiverson/dev/cleanup
local tests fixes
- Loading branch information
Showing
37 changed files
with
2,871 additions
and
2,726 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using static Postgrest.Exceptions.FailureHint.Reason; | ||
|
||
namespace Postgrest.Exceptions | ||
{ | ||
/// <summary> | ||
/// https://postgrest.org/en/v10.2/errors.html?highlight=exception#http-status-codes | ||
/// </summary> | ||
public static class FailureHint | ||
{ | ||
public enum Reason | ||
{ | ||
Unknown, | ||
NotAuthorized, | ||
ForeignKeyViolation, | ||
UniquenessViolation, | ||
Internal, | ||
UndefinedTable, | ||
UndefinedFunction | ||
} | ||
|
||
public static Reason DetectReason(PostgrestException pgex) | ||
{ | ||
if (pgex.Content == null) | ||
return Unknown; | ||
|
||
return pgex.StatusCode switch | ||
{ | ||
401 => NotAuthorized, | ||
403 when pgex.Content.Contains("apikey") => NotAuthorized, | ||
404 when pgex.Content.Contains("42883") => UndefinedTable, | ||
404 when pgex.Content.Contains("42P01") => UndefinedFunction, | ||
409 when pgex.Content.Contains("23503") => ForeignKeyViolation, | ||
409 when pgex.Content.Contains("23505") => UniquenessViolation, | ||
500 => Internal, | ||
_ => Unknown | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Net.Http; | ||
|
||
namespace Postgrest.Exceptions | ||
{ | ||
/// <summary> | ||
/// Errors from Postgrest are wrapped by this exception | ||
/// </summary> | ||
public class PostgrestException : Exception | ||
{ | ||
public PostgrestException(string? message) : base(message) { } | ||
public PostgrestException(string? message, Exception? innerException) : base(message, innerException) { } | ||
|
||
public HttpResponseMessage? Response { get; internal set; } | ||
|
||
public string? Content { get; internal set; } | ||
|
||
public int StatusCode { get; internal set; } | ||
|
||
public FailureHint.Reason Reason { get; private set; } | ||
|
||
public void AddReason() | ||
{ | ||
Reason = FailureHint.DetectReason(this); | ||
} | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Postgrest.Extensions | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Postgrest.Extensions | ||
{ | ||
|
Oops, something went wrong.