Skip to content

Commit

Permalink
Added error log
Browse files Browse the repository at this point in the history
  • Loading branch information
arumie committed Mar 5, 2024
1 parent c6b347d commit 66ef62b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions AiTestimonials/Api/AiTestimonialsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void RegisterAiTestimonialsEndpoints(this IEndpointRouteBuilder ro
route.MapGet("", GetTestimonialsAsync);
}

private static async Task<Ok<Identity>> PostGenerateAiTestimonialAsync(TestimonialInput input, [FromHeader(Name = "OPENAI_KEY")] string? openAIKey, AiTestimonialsService service, VercelPostgresRepository repo)
private static async Task<Ok<Identity>> PostGenerateAiTestimonialAsync(TestimonialInput input, [FromHeader(Name = "OPENAI_KEY")] string? openAIKey, AiTestimonialsService service, VercelPostgresRepository repo, ILoggerFactory loggerFactory)
{
service.SetupOpenAIService(openAIKey);
var testimonialId = (await repo.CreateNewTestimonialAsync(input)).ToString();
Expand All @@ -27,8 +27,11 @@ private static async Task<Ok<Identity>> PostGenerateAiTestimonialAsync(Testimoni
GenerateAiTestimonialAsync(testimonialId, input.Name, input.Skills, service, repo).Forget();
return TypedResults.Ok(new Identity() { Id = testimonialId.ToString() });
}
catch
catch (Exception e)
{
var logger = loggerFactory.CreateLogger("AiTestimonialsApi");
logger.LogError(e, "Unexpected error happened when trying to generate testimonial");

await repo.UpdateTestimonialAsync(TestimonialStatus.FAILED, testimonialId);
throw;
}
Expand Down

0 comments on commit 66ef62b

Please sign in to comment.