Skip to content

Error when Content-Type is text/plain; tool attempts to parse as JSON #676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
LinuxSuRen opened this issue May 8, 2025 · 2 comments · May be fixed by #677
Open

Error when Content-Type is text/plain; tool attempts to parse as JSON #676

LinuxSuRen opened this issue May 8, 2025 · 2 comments · May be fixed by #677
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@LinuxSuRen
Copy link
Owner

When sending a request with Content-Type text/plain;charset=UTF-8, the tool incorrectly attempts to parse the response as JSON and throws an error: "Unexpected token '测', '测试' is not valid JSON".

Steps to Reproduce

  1. Create a GET request with:

    • URL: http://localhost:8080/api/hello/message?key=testMessage
    • Header: Content-Type: text/plain;charset=UTF-8
  2. Send the request containing plain text content ("测试") in the body.

Expected Behavior

The tool should:

  1. Recognize the Content-Type header
  2. Display the plain text response without attempting JSON parsing
  3. Show the response text ("测试") in the output panel

Actual Behavior

  • Error message appears: "Unexpected token '测', '测试' is not valid JSON"
  • The response body is not properly displayed as plain text

Additional Context

  • Version: [Insert tool/version number here]
  • Environment: [Browser/OS if applicable]
  • API Endpoint: Shows "status code: 200" but fails to render content

Image

Proposed Fix

Modify the response handling to:

  1. Check the Content-Type header before processing
  2. Use appropriate renderer based on Content-Type
  3. Fallback to plain text display if content isn't parseable as JSON
@LinuxSuRen LinuxSuRen added bug Something isn't working good first issue Good for newcomers labels May 8, 2025
@KariHall619
Copy link

Hey! I can take this.

I’ve actually been testing stuff like this lately while working on the AI assistant for Atest — handling text/plain properly would help avoid weird edge case bugs later on. Seems like a good one to sort out early.

Let me know if there’s anything I should be careful about!

@LinuxSuRen
Copy link
Owner Author

hi @KariHall619 thanks for your time. In most cases, an API will return data in JSON format. But we cannot see the data if it's plain/text. No further particular things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants