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

Display API errors on AngularJS pages #2378

Merged
merged 2 commits into from
Aug 8, 2024

Conversation

zackgalbreath
Copy link
Contributor

No description provided.

@zackgalbreath zackgalbreath force-pushed the display_api_errors_for_angular_pages branch from da6ffcd to 2dd4a8f Compare August 7, 2024 21:07
@@ -63,7 +63,7 @@ function can_access_project($projectid): bool

$logged_in = Auth::check();
if ($logged_in) {
abort(403, 'You do not have permission to access this page.');
abort(404, 'Project not found.');
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this entire function could be replaced with the following:

function can_access_project($projectid): bool
{
    Gate::authorize('view-project', $project);
    return true;
}

Gate::authorize will automatically handle throwing the right type of error (either 401 or 403 depending on login status).

This function is on my shortlist of functions to refactor eventually but doing this would be a decent immediate solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unconditionally using Gate::authorize got rid of the requirelogin:1 redirect logic we have. But I do like using this function rather than abort() for consistent error messaging.

@zackgalbreath zackgalbreath force-pushed the display_api_errors_for_angular_pages branch from 2dd4a8f to ba44f3b Compare August 8, 2024 13:56
@williamjallen williamjallen added this pull request to the merge queue Aug 8, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 8, 2024
@williamjallen williamjallen added this pull request to the merge queue Aug 8, 2024
Merged via the queue into releases/3.5 with commit 8bb721b Aug 8, 2024
6 checks passed
@williamjallen williamjallen deleted the display_api_errors_for_angular_pages branch August 8, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants