LinguistAI / user

1 stars 0 forks source link

refactor(LINGUIST-486): Log dictionary's response #94

Open KardelenCeren opened 4 months ago

KardelenCeren commented 4 months ago

Dictionary service's responses are logged. For example, for the 404 error, this is logged:

Word kjjj is not found in the dictionary. Dictionary service's error: {"error":"error","msg":"Word not found: kjjj","timestamp":"2024-05-16T04:57:21+03:00","status":404}

Similarly, all other responses log the dictionary response.

To parse the response, I tried .onStatus and exchangeFilterResponseProcessor methods, but if we throw a Mono.error(new NotFoundException(body)) then this error is caught in the catch(RuntimeError) block, not the NotFoundError block, since Mono errors are thrown as RuntimeError's children errors within the WebClient's reactive chain.

Instead, we parse the exception that is mentioned here: https://www.baeldung.com/spring-5-webclient#4-getting-a-response

I looked at the following solutions: https://www.baeldung.com/spring-webclient-get-response-body https://stackoverflow.com/questions/76057817/the-type-httpstatus-does-not-define-iserrorhttpstatuscode-defined-here-in-java https://www.baeldung.com/spring-webflux-errors https://stackoverflow.com/questions/63701274/how-to-get-custom-error-body-message-in-webclient-properly

There might be better solutions out there, but this now logs the dictionary response.

NOTE: Do NOT merge this PR before the dev to main PR, since this code will cause errors and this PR is just to be able to log in more detail, it does not actually solve the problem.

can-aslan commented 4 months ago

How will the erros be fixed after merging the dev-to-main PR?

KardelenCeren commented 4 months ago

How will the erros be fixed after merging the dev-to-main PR?

We will try sending add word requests from the frontend, and check the logs to figure out the problem. My device's expo only works through "tunnel" so I cannot connect the local frontend to the local backend.

It will be through trial and error since the 400 error only comes up sometimes :/