Skip to content

Commit 1bb5196

Browse files
authored
Merge pull request #70 from wiverson/change-from-internal
Minor Unity Related Fixes
2 parents d947e24 + 3312055 commit 1bb5196

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Postgrest/Exceptions/FailureHint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public enum Reason
1515
NotAuthorized,
1616
ForeignKeyViolation,
1717
UniquenessViolation,
18-
Internal,
18+
ServerError,
1919
UndefinedTable,
2020
UndefinedFunction,
2121
InvalidArgument
@@ -34,7 +34,7 @@ 404 when pgex.Content.Contains("42883") => UndefinedTable,
3434
404 when pgex.Content.Contains("42P01") => UndefinedFunction,
3535
409 when pgex.Content.Contains("23503") => ForeignKeyViolation,
3636
409 when pgex.Content.Contains("23505") => UniquenessViolation,
37-
500 => Internal,
37+
500 => ServerError,
3838
_ => Unknown
3939
};
4040
}

Postgrest/Helpers.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ internal static class Helpers
2222
{
2323
private static readonly HttpClient Client = new HttpClient();
2424

25+
private static readonly Guid AppSession = Guid.NewGuid();
26+
2527
/// <summary>
2628
/// Helper to make a request using the defined parameters to an API Endpoint and coerce into a model.
2729
/// </summary>
@@ -137,7 +139,18 @@ public static Dictionary<string, string> PrepareRequestHeaders(HttpMethod method
137139

138140
if (!headers.ContainsKey("X-Client-Info"))
139141
{
140-
headers.Add("X-Client-Info", Util.GetAssemblyVersion(typeof(Client)));
142+
try
143+
{
144+
// Default version to match other clients
145+
// https://github.com/search?q=org%3Asupabase-community+x-client-info&type=code
146+
headers.Add("X-Client-Info", $"postgrest-csharp/{Util.GetAssemblyVersion(typeof(Client))}");
147+
}
148+
catch (Exception)
149+
{
150+
// Fallback for when the version can't be found
151+
// e.g. running in the Unity Editor, ILL2CPP builds, etc.
152+
headers.Add("X-Client-Info", $"postgrest-csharp/session-{AppSession}");
153+
}
141154
}
142155

143156
return headers;

Postgrest/Models/BaseModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public abstract class BaseModel
4343
public virtual Task Delete<T>(CancellationToken cancellationToken = default) where T : BaseModel, new()
4444
{
4545
if (BaseUrl == null)
46-
throw new PostgrestException("`BaseUrl` should be set in the model.") { Reason = FailureHint.Reason.Internal };
46+
throw new PostgrestException("`BaseUrl` should be set in the model.") { Reason = FailureHint.Reason.ServerError };
4747

4848
var client = new Client(BaseUrl, RequestClientOptions)
4949
{

0 commit comments

Comments
 (0)