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

Add more detailed error responses from original request #8

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Add more detailed error responses from original request #8

wants to merge 1 commit into from

Conversation

noahjahn
Copy link

@noahjahn noahjahn commented Sep 18, 2020

Use case:
For an API request that responds back with detailed error messages for how to correct an issue, or exactly what went wrong, it would be nice to have the original response body returned when an Exception is thrown.

I also chose to add the status code from the HTTP request as well. A good example of this would be to display different messages to the user in a template for why the request failed.

My specific use case for this is searching for a term in an API. If the term is not found the API responds with 404, since the resource could not be found. I wanted to be able to handle this on the front end:

{% if response.statusCode == 404 %}
    <p class="text-warning">Record not found name {{record}} not found</p>
{% elseif response.statusCode == 400 %}
    <p class="text-danger">Record type is not supported</p>
{% else %}
    <p class="text-danger">{{error|json_encode(constant('JSON_PRETTY_PRINT'))}}</p>
{% endif %}

Side notes:
I didn't see any documentation on contributing to this project. Hoping this is okay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant