Skip to content

fix: show toast on errors with empty response#2750

Merged
Chartman123 merged 2 commits into
mainfrom
fix/submit-error-toast
Jun 17, 2025
Merged

fix: show toast on errors with empty response#2750
Chartman123 merged 2 commits into
mainfrom
fix/submit-error-toast

Conversation

@hamza221
Copy link
Copy Markdown
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
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
@hamza221 hamza221 force-pushed the fix/submit-error-toast branch from 059261a to 10dd0ad Compare May 21, 2025 12:47
@Chartman123
Copy link
Copy Markdown
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);
}
}
}

@hamza221
Copy link
Copy Markdown
Contributor Author

hamza221 commented Jun 12, 2025

Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 12, 2025

Codecov Report

Attention: Patch coverage is 33.33333% with 18 lines in your changes missing coverage. Please review.

Project coverage is 45.39%. Comparing base (699f8f7) to head (51e3427).
Report is 50 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2750      +/-   ##
============================================
- Coverage     45.58%   45.39%   -0.20%     
- Complexity      984      987       +3     
============================================
  Files            79       79              
  Lines          3565     3580      +15     
============================================
  Hits           1625     1625              
- Misses         1940     1955      +15     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Chartman123 Chartman123 merged commit c2f2d40 into main Jun 17, 2025
52 of 54 checks passed
@Chartman123 Chartman123 deleted the fix/submit-error-toast branch June 17, 2025 08:49
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