Skip to content

Conversation

@javorosas
Copy link
Member

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new PreviewPdfAsync method to enable invoice PDF preview functionality before stamping. This feature allows users to preview how an invoice PDF will look without actually creating the invoice.

Key changes:

  • Added PreviewPdfAsync method to InvoiceWrapper class
  • Added corresponding route helper in InvoiceRouter
  • Updated version to 4.10.0

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
facturapi-net.csproj Version bump to 4.10.0
Wrappers/InvoiceWrapper.cs Added PreviewPdfAsync method implementation
Router/InvoiceRouter.cs Added PreviewPdf route helper method
CHANGELOG.md Added changelog entry for new feature

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +189 to +197
var response = await client.GetAsync(Router.PreviewPdf(query));
if (!response.IsSuccessStatusCode)
{
var resultString = await response.Content.ReadAsStringAsync();
var error = JsonConvert.DeserializeObject<JObject>(resultString, this.jsonSettings);
throw new FacturapiException(error["message"].ToString());
}
var stream = await response.Content.ReadAsStreamAsync();
return stream;
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method doesn't dispose of the HTTP response, which can lead to resource leaks. The response should be wrapped in a using statement or the stream should be copied to avoid keeping the HTTP connection open.

Suggested change
var response = await client.GetAsync(Router.PreviewPdf(query));
if (!response.IsSuccessStatusCode)
{
var resultString = await response.Content.ReadAsStringAsync();
var error = JsonConvert.DeserializeObject<JObject>(resultString, this.jsonSettings);
throw new FacturapiException(error["message"].ToString());
}
var stream = await response.Content.ReadAsStreamAsync();
return stream;
using (var response = await client.GetAsync(Router.PreviewPdf(query)))
{
if (!response.IsSuccessStatusCode)
{
var resultString = await response.Content.ReadAsStringAsync();
var error = JsonConvert.DeserializeObject<JObject>(resultString, this.jsonSettings);
throw new FacturapiException(error["message"].ToString());
}
var responseStream = await response.Content.ReadAsStreamAsync();
var memoryStream = new MemoryStream();
await responseStream.CopyToAsync(memoryStream);
memoryStream.Position = 0;
return memoryStream;
}

Copilot uses AI. Check for mistakes.
{
var resultString = await response.Content.ReadAsStringAsync();
var error = JsonConvert.DeserializeObject<JObject>(resultString, this.jsonSettings);
throw new FacturapiException(error["message"].ToString());
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference exception if the response JSON doesn't contain a 'message' field. The code should check if error['message'] exists before calling ToString().

Copilot uses AI. Check for mistakes.
@javorosas javorosas merged commit 0d7ac41 into main Sep 11, 2025
@javorosas javorosas deleted the feat/pdf-preview branch September 11, 2025 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants