You are browsing as a guest. Sign up (or log in) to start making projects!

3h 7m 45s logged

Devlog

There was a small (or big) problem in my playground.
If an error was returned in the response, you could only see it if your app handled it or by printing the response.

That’s why I added an error logger.
It can show errors in two ways:

  • Terminal
  • Log file

How it works

There were two ways of doing it (from what I learned):

  • Middleware that captures all responses (this could be helpful in the future).
  • Exception handlers (this is what I chose).

I use two handlers:

  • @app.exception_handler(RequestValidationError)
  • @app.exception_handler(HTTPException)

It was a horrible time searching for why it didn’t work.

At first, I worked in a separate file, but I couldn’t get the (fastapi) app variable into those functions.
So I copied them into main file to make them work first.
I had to change some JSON responses to HTTPException to make the second handler work.

After I captured the first request and printed it, I worked on one function that writes a log and another that prints to the terminal. I also created a class to store useful data.

It works like this:

Exception handler->
        
 ->Put data into class ->

  ->Create response ->
        	 ->Return response
        	 ->Create a background task that logs the error

I create a background task so the response doesn’t wait or even worse fails

In the end I found that I can wrap these func with this simple func to make them work in different file
def setup_error_logging(app: FastAPI):

Added a config option:

  • To disable it completely.
  • To disable only the log file.
    It also bypasses all internal endpoints to make the logs more readable.

The best fail… 😅

I returned an exception instead of raising it.
I spent a good 15 minutes wondering why the response had status code 200 with a JSON body saying status code 400.

response changes

I also checked how the authorization errors look and added two new ones:

  • Missing Authorization header.
  • Invalid vcc-api-key header.

WIKI (not counted)

I focus on making a GitHub wiki (new docs)
After ending them and the error logger.

Its time for the first ship !!!!!!!

Nest instability:

I made a backup server : https://frog01-21185.wykr.es/
Its not ideal one, bc some asian countries are blocked but its shouldn’t have any downtime (I hope so)

If an Admin read it why I must copy enter from different text input 😭

0
12

Comments 0

No comments yet. Be the first!