Skip to content
Snippets Groups Projects
Commit ff8dff63 authored by Sergiu-Lucian Petrica's avatar Sergiu-Lucian Petrica
Browse files

Implemented redirection to form when exception is thrown, with a generic error...

Implemented redirection to form when exception is thrown, with a generic error showing to the user + logging error message
parent 79a04105
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ namespace SGalinski\SgJobs\Controller;
use SGalinski\SgJobs\Domain\Model\JobApplication;
use SGalinski\SgMail\Service\MailTemplateService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Resource\DuplicationBehavior;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility;
......@@ -92,13 +92,20 @@ class JoblistController extends ActionController {
* Renders the application form with an optional job
*
* @param JobApplication $applyData
* @param string $error
*/
public function applyFormAction(JobApplication $applyData = NULL) {
public function applyFormAction(JobApplication $applyData = NULL, $error = NULL) {
if ($this->request->getOriginalRequest()) {
$uploadedFiles = $this->request->getOriginalRequest()->getArguments()['uploadedFiles'];
$this->view->assign('uploadedFiles', $uploadedFiles);
}
if ($error !== NULL) {
$logger = GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
$logger->log(LogLevel::ALERT, $error, $applyData);
$this->view->assign('error', 1);
}
$jobId = $this->request->getArguments()['jobData']['uid'];
if (!empty($jobId)) {
$jobData = $this->jobRepository->findByUid($jobId);
......@@ -146,11 +153,9 @@ class JoblistController extends ActionController {
->setTargetPageUid($redirectPageId)
->build();
$this->redirectToUri($uri);
} catch (\Exception $exception) {
// possible errors, because of wrong mails (maybe log that somewhere? Does this makes sense?)
GeneralUtility::makeInstance(FlashMessage::class, $exception->getMessage());
$this->redirect('applyFormAction');
$this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]);
}
}
......@@ -178,8 +183,7 @@ class JoblistController extends ActionController {
$this->handleFileUpload('certificates', $uniqueFolderName);
} catch (\Exception $exception) {
// possible errors, because of wrong mails
GeneralUtility::makeInstance(FlashMessage::class, $exception->getMessage());
$this->redirect('applyFormAction');
$this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]);
}
$propertyMappingConfiguration = $this->arguments->getArgument('applyData')->getPropertyMappingConfiguration();
$propertyMappingConfiguration->forProperty('coverLetter')->allowAllProperties();
......@@ -363,8 +367,7 @@ class JoblistController extends ActionController {
fputcsv($file, $dataToInsertArr);
fclose($file);
} catch (\RuntimeException $exception) {
GeneralUtility::makeInstance(FlashMessage::class, $exception->getMessage());
$this->redirect('applyFormAction');
$this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]);
}
}
......
......@@ -210,6 +210,10 @@
<source>Female</source>
<target>Weiblich</target>
</trans-unit>
<trans-unit id="frontend.apply.error.general" approved="yes">
<source>An error has occured</source>
<target>Ein Fehler ist aufgetreten</target>
</trans-unit>
<trans-unit id="frontend.applyNow" approved="yes">
<source>Apply online now</source>
<target>Jetzt online bewerben</target>
......
......@@ -159,6 +159,9 @@
<trans-unit id="frontend.apply.gender.female">
<source>Female</source>
</trans-unit>
<trans-unit id="frontend.apply.error.general">
<source>An error has occured</source>
</trans-unit>
<trans-unit id="frontend.applyNow">
<source>Apply online now</source>
</trans-unit>
......
<f:layout name="Default" />
<f:section name="main">
<f:flashMessages />
<f:form action="apply" controller="Joblist" method="post" objectName="applyData" object="{applyData}" enctype="multipart/form-data">
<f:if condition="{error}">
<div class="errormessage">
<f:translate key="frontend.apply.error.general" />
</div>
</f:if>
<f:if condition="{job}">
<f:form.hidden value="{job.jobId}" property="jobId" />
<label for="apply-title"><f:translate key="frontend.apply.title" /></label>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment