Gracefully fail when unable to access a mailbox
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 348
- Avg merge
- 12h 28m
- Merged PRs (30d)
- 91
Description
Expected behavior
If the apps/mail/api/mailboxes?accountId={accountId} endpoint is unable to access a mailbox for whatever reason, the fail should be handled gracefully and the user should be notified.
Actual behavior
The exception is thrown in MailboxSync::sync but isn't handled in MailManager but instead ignored.
To do
- Handle the exception upwards to the controller
- Add a JSONResponse::fail with the correct response data
- Add an indication to the frontend that notifies the user of an issue with this account
In lib/Service/MailManager.php
/**
* @param Account $account
*
* @return Mailbox[]
* @throws ServiceException
*/
public function getMailboxes(Account $account): array {
try {
$this->mailboxSync->sync($account, $this->logger);
} catch( ServiceException $e) {
throw $e;
}
return $this->mailboxMapper->findAll($account);
}
Some code from debugging this a bit:
In lib/Controller/MailboxesController.php
/**
* @NoAdminRequired
* @TrapError
*
* @param int $accountId
*
* @return JSONResponse
*
* @throws ClientException
* @throws ServiceException
*/
public function index(int $accountId): JSONResponse {
$account = $this->accountService->find($this->currentUserId, $accountId);
try {
$mailboxes = $this->mailManager->getMailboxes($account);
} catch(ServiceException $e) {
return HttpJsonResponse::fail(['Could not access mailbox for account ' . $account->getEMailAddress()]);
}
return new JSONResponse([
'id' => $accountId,
'email' => $account->getEmail(),
'mailboxes' => $mailboxes,
'delimiter' => reset($mailboxes)->getDelimiter(),
]);
}
src/components/Dashboard.vue needs to handle this error as well as the mail app.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/Service/MailManager.php and lib/Controller/MailboxesController.php for the apps/mail/api/mailboxes?accountId={accountId} flow, then inspect src/components/Dashboard.vue. Trace the ServiceException from MailboxSync::sync and determine the expected failure response and frontend notification behavior. Done means the exception reaches the controller, the endpoint returns the appropriate JSON failure, and both the dashboard and mail app notify the user.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, php
- Domain
- api, backend, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100