Skip to content
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

Bruno crashes when parsing non-JSON success response #3119

Closed
2 tasks done
TheoD02 opened this issue Sep 17, 2024 · 1 comment · Fixed by #3120
Closed
2 tasks done

Bruno crashes when parsing non-JSON success response #3119

TheoD02 opened this issue Sep 17, 2024 · 1 comment · Fixed by #3120
Labels
bug Something isn't working

Comments

@TheoD02
Copy link
Contributor

TheoD02 commented Sep 17, 2024

I have checked the following:

  • I use the newest version of bruno.
  • I've searched existing issues and found nothing related to my issue.

Describe the bug

Bruno crashes when handling a server response that returns "true" with the application/json content type. This occurs when sending a request to the Dokploy API in my case (/api/application.update). The issue seems related to Bruno attempting to parse the "true" response, which is not valid JSON, leading to a crash.

Steps to Reproduce:

  1. Send a request to an endpoint that responds with "true" and sets the Content-Type header to application/json.
  2. Observe that Bruno crashes after receiving this response.
  3. Confirm that Bruno handles responses properly when valid JSON (e.g., a 400 Bad Request response) is returned from the server.

Expected Behavior:
Bruno should be able to handle and display non-JSON responses like "true" without crashing, especially when the content type is application/json.

Actual Behavior:

  • When the response is "true", Bruno crashes due to invalid JSON parsing.
  • If the server returns valid JSON (e.g., an error response), Bruno displays the response without issues.

Additional Context:

  • The response "true" is sent with the application/json content type, which is technically incorrect, but Bruno should still handle this gracefully.

e.g.:
Returning this in Symfony Controller will make bruno crash

public function __invoke(): JsonResponse
{
    return $this->json(true);
}

.bru file to reproduce the bug

No response

Screenshots/Live demo link

image

@TheoD02 TheoD02 added the bug Something isn't working label Sep 17, 2024
@TheoD02 TheoD02 changed the title Bruno API Client crashes when parsing non-JSON success response Bruno crashes when parsing non-JSON success response Sep 17, 2024
TheoD02 added a commit to TheoD02/bruno that referenced this issue Sep 17, 2024
helloanoop pushed a commit that referenced this issue Sep 18, 2024
* fix: handle case of text when invalid JSON (#3119)

* don't stringify if json is invalid, and maintain indentation if stringified

* stringify check

---------

Co-authored-by: lohit <[email protected]>
@helloanoop
Copy link
Contributor

I have merged the PR that fixes this issue.
We will release a patch in the next couple of hours.

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

Successfully merging a pull request may close this issue.

2 participants