Skip to content

Commit

Permalink
Wrap error deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
nakedmcse committed Mar 20, 2024
1 parent c7f9a43 commit 02ec2a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion waifuVault-csharp-api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<PackageId>Waifuvault</PackageId>
<Version>1.1.9</Version>
<Version>1.2.0</Version>
<Authors>Walker Aldridge (walker@waifuvault.moe)</Authors>
<Company>waifuvault.moe</Company>
<PackageTags>waifuvault;temp file hosting;waifu;vault</PackageTags>
Expand Down
9 changes: 7 additions & 2 deletions waifuvault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,20 @@ private static async void checkError(HttpResponseMessage? response, bool isDownl
}
if(!response.IsSuccessStatusCode) {
var body = await response.Content.ReadAsStringAsync();
var error = JsonSerializer.Deserialize<ErrorResponse>(body);
ErrorResponse error = new ErrorResponse();
try {
error = JsonSerializer.Deserialize<ErrorResponse>(body);

Check warning on line 112 in waifuvault.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
} catch {
error.name = "Deserialization Failed";

Check warning on line 114 in waifuvault.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
error.message = body;
}
if(response.StatusCode == HttpStatusCode.Forbidden && isDownload) {
throw new Exception("Password is incorrect");
}
throw new Exception($"Error {response.StatusCode.ToString()} ({error.name}:{error.message})");
}
}


}

public class FileUpload
Expand Down

0 comments on commit 02ec2a7

Please sign in to comment.