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

fix: Return proper http response codes for errors #192

Conversation

komen205
Copy link
Contributor

Description

Fixes #171

Type of change

  • New feature (added a non-breaking change which adds functionality)

How Has This Been Tested?

  • Tested locally with a valid username
  • Tested locally with an invalid username
  • Ran tests with composer test
  • Added or updated test cases to test new features

Checklist:

  • I have checked to make sure no other pull requests are open for this issue
  • The code is properly formatted and is consistent with the existing code style
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Screenshots

@komen205 komen205 force-pushed the Return-proper-http-response-codes-for-errors branch from 2360079 to 224039d Compare November 13, 2021 15:05
@komen205
Copy link
Contributor Author

@DenverCoder1 let me know if this works

Copy link
Owner

@DenverCoder1 DenverCoder1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error codes also need to be set when throwing the exception

e.g. for errors that should return 404 response, 404 should be passed as the $code parameter.

throw new InvalidArgumentException("Could not find a user with that name.", 404);

src/card.php Outdated Show resolved Hide resolved
src/card.php Outdated Show resolved Hide resolved
@komen205 komen205 force-pushed the Return-proper-http-response-codes-for-errors branch from e9c343a to 5a81b86 Compare December 1, 2021 11:03
Copy link
Owner

@DenverCoder1 DenverCoder1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! This is a very helpful contribution.

There's still a couple suggestions earlier about the spelling of the parameter name.

Also, on line 21 of index.php, maybe a 500 could be sent when the token is missing from the configuration.

if (!isset($_SERVER["TOKEN"])) {
    $message = file_exists(dirname(__DIR__ . '../.env', 1))
        ? "Missing token in config. Check Contributing.md for details."
        : ".env was not found. Check Contributing.md for details.";
-    renderOutput($message);
+    renderOutput($message, 500);
}

komen205 and others added 4 commits December 14, 2021 22:03
Co-authored-by: Jonah Lawrence <jonah@freshidea.com>
Co-authored-by: Jonah Lawrence <jonah@freshidea.com>
Copy link
Owner

@DenverCoder1 DenverCoder1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for the contribution 🎉

@DenverCoder1 DenverCoder1 changed the title Return proper http response codes for errors fix: Return proper http response codes for errors Dec 15, 2021
@DenverCoder1 DenverCoder1 merged commit 32f4a06 into DenverCoder1:main Dec 15, 2021
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.

Return proper HTTP response codes for errors
2 participants