Skip to content

fix: show toast on errors with empty response #2750

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hamza221
Copy link
Contributor

Repro:

Status code Response
image image

On submit, Toast doesn't show, leaving the user unsure whether the submission went through

@hamza221 hamza221 self-assigned this May 21, 2025
@hamza221 hamza221 added bug Something isn't working 3. to review Waiting for reviews labels May 21, 2025
@hamza221 hamza221 requested review from Chartman123 and susnux May 21, 2025 12:44
@hamza221 hamza221 force-pushed the fix/submit-error-toast branch from 059261a to 10dd0ad Compare May 21, 2025 12:47
@Chartman123
Copy link
Collaborator

Here's more information about the error itself that leads to the missing message in the frontend:

Error message in the logfile:

{"reqId":"47nAIhY7pkRZiS7G2tFZ","level":3,"time":"2025-05-21T12:39:17+00:00","remoteAddr":"192.168.21.5","user":"user1","app":"PHP","method":"POST","url":"/ocs/v2.php/apps/forms/api/v3/forms/1/submissions","message":"Class OCA\\Notifications\\FakeUser contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (OCP\\IUser::canChangeEmail) at /var/www/html/apps/notifications/lib/FakeUser.php#13","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36","version":"32.0.0.0","data":{"app":"PHP"}}

The OCA\Notifications\ part of the log message leads to the ActivityManager that is called in newSubmission and updateSubmission via notifyNewSubmission in FormsService. So we should probably add some error handling here

public function notifyNewSubmission(Form $form, Submission $submission): void {
$shares = $this->getShares($form->getId());
$this->activityManager->publishNewSubmission($form, $submission->getUserId());
foreach ($shares as $share) {
if (!in_array(Constants::PERMISSION_RESULTS, $share['permissions'])) {
continue;
}
$this->activityManager->publishNewSharedSubmission($form, $share['shareType'], $share['shareWith'], $submission->getUserId());
}
$this->eventDispatcher->dispatchTyped(new FormSubmittedEvent($form, $submission));
}

or here

public function publishNewSubmission(Form $form, string $submitterID): void {
$event = $this->manager->generateEvent();
$event->setApp($this->appName)
->setType(ActivityConstants::TYPE_NEWSUBMISSION)
->setAffectedUser($form->getOwnerId())
->setAuthor($submitterID)
->setSubject(ActivityConstants::SUBJECT_NEWSUBMISSION, [
'userId' => $submitterID,
'formTitle' => $form->getTitle(),
'formHash' => $form->getHash()
])
->setObject('form', $form->getId());
$this->manager->publish($event);
}
/**
* Publish a new-Submission Activity for shared forms
*
* @param Form $form The affected Form
* @param string $submitterID ID of the User who submitted the form. Can also be our 'anon-user-'-ID
*/
public function publishNewSharedSubmission(Form $form, int $shareType, string $shareWith, string $submitterID): void {
$users = [];
switch ($shareType) {
case IShare::TYPE_USER:
$users[] = $shareWith;
break;
case IShare::TYPE_GROUP:
$group = $this->groupManager->get($shareWith);
if ($group !== null) {
$users = array_map(fn (IUser $user) => $user->getUID(), $group->getUsers());
}
break;
case IShare::TYPE_CIRCLE:
$users = $this->circlesService->getCircleUsers($shareWith);
break;
}
foreach ($users as $userId) {
$event = $this->manager->generateEvent();
$event->setApp($this->appName)
->setType(ActivityConstants::TYPE_NEWSHAREDSUBMISSION)
->setAffectedUser($userId)
->setAuthor($submitterID)
->setSubject(ActivityConstants::SUBJECT_NEWSUBMISSION, [
'userId' => $submitterID,
'formTitle' => $form->getTitle(),
'formHash' => $form->getHash()
])
->setObject('form', $form->getId());
$this->manager->publish($event);
}
}
}

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

Successfully merging this pull request may close these issues.

2 participants