Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
namespace Postgrest.Tests.Requests;

/// <summary>
/// A 2xx body that isn't JSON throws a <see cref="PostgrestException" /> carrying the body and status.
/// A body that isn't JSON throws a <see cref="PostgrestException" /> carrying the body and status,
/// and a 414 is reported as <see cref="FailureHint.Reason.UriTooLong" />.
/// </summary>
[TestClass]
[TestCategory("Contract")]
Expand Down Expand Up @@ -60,6 +61,15 @@ await act.Should().ThrowAsync<PostgrestException>()
"postgrest-js handles rpc responses the same way (#260)");
}

[TestMethod]
public async Task Get_ShouldReportUriTooLong_Given414()
{
this.server.Given(Request.Create().WithPath("/todos")).RespondWith(Response.Create().WithStatusCode(414).WithBody("URI too long"));
var act = () => this.client.Table<Todo>().Get();
await act.Should().ThrowAsync<PostgrestException>()
.Where(exception => exception.Reason == FailureHint.Reason.UriTooLong, "the gateway answers an overlong URL with a 414 (#235)");
}

private void MockProxyErrorPage(string path) =>
this.server.Given(Request.Create().WithPath(path))
.RespondWith(Response.Create().WithStatusCode(200).WithBody(ProxyErrorPage));
Expand Down
4 changes: 3 additions & 1 deletion packages/Postgrest/Postgrest/Exceptions/FailureHint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public enum Reason
ServerError,
UndefinedTable,
UndefinedFunction,
InvalidArgument
InvalidArgument,
UriTooLong
}

public static Reason DetectReason(PostgrestException pgex)
Expand All @@ -34,6 +35,7 @@ 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,
414 => UriTooLong,
500 => ServerError,
_ => Unknown
};
Expand Down
1 change: 1 addition & 0 deletions packages/Postgrest/Postgrest/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
Supabase.Postgrest.Exceptions.FailureHint.Reason.UriTooLong = 8 -> Supabase.Postgrest.Exceptions.FailureHint.Reason
Loading