Giter Club home page Giter Club logo

Comments (3)

dfrankow avatar dfrankow commented on June 14, 2024

And, when this error occurs, I'd love to see the POST body!

from drf-api-logger.

vishalanandl177 avatar vishalanandl177 commented on June 14, 2024

You probably get the same response from API as well. As we can see from the screenshot you shared, the response is not JSON.
You are using POST call with no JSON data (body). Use empty JSON {} and the call POST API.
The DRF API Logger is only for JSON-type data.
Use the postman client app to call the API and then compare the response from the DRF API Logger Admin panel.

If you want to log extra information that DRF API Logger cannot log, use signals and log the data manually.
How to use signals and how to log data in the DRF API Logger model? Check the README.md for more information.

from drf-api-logger.

dfrankow avatar dfrankow commented on June 14, 2024

The response is proper JSON. It's the request that has invalid JSON. I am not calling with an empty body. It has a body that is invalid JSON. Below is more info about an example.

Request 2 below is a POST request to DRF, and has a non-empty POST body that is not logged by DRF API Logger. Perhaps you're saying this library only logs valid JSON POST bodies. I'm saying that it would be helpful if it logged the POST body even if it is invalid JSON. In fact, that's very helpful because that's a case where I really want to see the body!

I would re-open this issue if I could. I'll read the README about how to try to use signals to log the body, but I would appreciate any help.

===========================

  1. Sending a request that works, using httpie:
$ cat ok.json
{ "question": "?", "creator": "example", "name": "example name" }
$ cat ok.json | http POST http://localhost:8000/api/v1/polls/
HTTP/1.1 201 Created
...
{
    "category": "",
    "created_dt": "2021-03-05T14:37:02.627205Z",
    "creator": "example",
    "id": "ABR5OZIwAhQ",
    "name": "example name",
    "question": "?"
}

image

  1. Sending a request with a POST body that is invalid JSON (extra double quote):
$ cat not_ok.json
{ "question": "?", "creator": "example"", "name": "example name" }
$ cat not_ok.json | http POST http://localhost:8000/api/v1/polls/
HTTP/1.1 400 Bad Request
...
{
    "detail": "JSON parse error - Expecting ',' delimiter: line 1 column 40 (char 39)"
}

It had a POST body, but that body was not logged:

image

from drf-api-logger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.