Fixed Swiftmailer not catching Exceptions
This commit is contained in:
parent
2b33856e17
commit
80f83362f2
|
@ -130,14 +130,18 @@ class App extends Application
|
|||
$matches = 'Available methods are unknown.';
|
||||
}
|
||||
$message = json_encode(['status' => 'error', 'message' => 'Method not allowed', 'allowedMethods' => $matches, 'requestedMethod' => $request->getMethod(), 'code' => $code]);
|
||||
$this->log($e->getMessage(), ['code' => $code], \Symfony\Bridge\Monolog\Logger::WARNING);
|
||||
break;
|
||||
case 500:
|
||||
$message = json_encode(['status' => 'error', 'message' => $e->getMessage(), 'code' => $code]);
|
||||
$message = json_encode(['status' => 'error', 'message' => 'Critical Error', 'code' => $code]);
|
||||
$this->log($e->getMessage(), ['code' => $code], \Symfony\Bridge\Monolog\Logger::CRITICAL);
|
||||
break;
|
||||
default:
|
||||
$message = json_encode(['status' => 'error', 'message' => $e->getMessage(), 'code' => $code]);
|
||||
$this->log($e->getMessage(), ['code' => $code], \Symfony\Bridge\Monolog\Logger::ERROR);
|
||||
break;
|
||||
}
|
||||
|
||||
return new \Symfony\Component\HttpFoundation\Response($message, $code);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ $app
|
|||
'console.version' => '0.0.1',
|
||||
'console.project_directory' => $app->getAppDirectory(),
|
||||
]);
|
||||
|
||||
$app['swiftmailer.use_spool'] = false;
|
||||
if(false === getenv('SPARKPOST_API_KEY') && null !== $app->config('app.smtp_host')) {
|
||||
$app['swiftmailer.options'] = [
|
||||
'host' => $app->config('app.smtp_host'),
|
||||
|
|
|
@ -137,7 +137,7 @@ class ApiControllerProvider implements ControllerProviderInterface {
|
|||
$contactFormName = $contactFormData['contact']['name'];
|
||||
$contactFormEmail = $contactFormData['contact']['email'];
|
||||
$contactFormMessage = $contactFormData['contact']['message'];
|
||||
$request->getSession()->remove('_csrf/contact');
|
||||
|
||||
$failures = '';
|
||||
|
||||
$sent = $app['mailer']->send(\Swift_Message::newInstance()
|
||||
|
@ -147,6 +147,7 @@ class ApiControllerProvider implements ControllerProviderInterface {
|
|||
->setBody($contactFormMessage)
|
||||
, $failures);
|
||||
if($sent > 0) {
|
||||
$request->getSession()->remove('_csrf/contact');
|
||||
return new JsonResponse([
|
||||
'status' => 'success',
|
||||
'message' => 'Message successfully sent.',
|
||||
|
|
|
@ -16,6 +16,7 @@ use Sikofitt\Form\Type\ContactType;
|
|||
use Silex\Api\ControllerProviderInterface;
|
||||
use Silex\Application;
|
||||
use Symfony\Component\Form\FormFactory;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
|
@ -63,6 +64,22 @@ class ResumeControllerProvider implements ControllerProviderInterface
|
|||
]);
|
||||
});
|
||||
|
||||
$controllers->post('/', function(Request $request) use ($app) {
|
||||
$contactFormData = $request->request->all();
|
||||
$contactFormName = $contactFormData['contact']['name'];
|
||||
$contactFormEmail = $contactFormData['contact']['email'];
|
||||
$contactFormMessage = $contactFormData['contact']['message'];
|
||||
$sent = $app['mailer']->send(\Swift_Message::newInstance()
|
||||
->setSubject('[Resume] Message')
|
||||
->setFrom([$contactFormEmail => $contactFormName])
|
||||
->setTo($app->config('app.email'))
|
||||
->setBody($contactFormMessage)
|
||||
, $failures);
|
||||
dump($failures);
|
||||
dump($sent);
|
||||
return new JsonResponse(['failures' => $failures, 'sent' => (bool)$sent]);
|
||||
});
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ jq(document).ready(function (jq) {
|
|||
contactModal.show();
|
||||
jq.post(jq(this).attr('action'), jq(this).serialize(), function(response) {
|
||||
if(response.status !== 'success') {
|
||||
resp = response;
|
||||
jq('#' + response.id).addClass('uk-form-danger');
|
||||
UIkit.notify('<i class="uk-icon uk-icon-frown-o uk-icon-justify uk-margin-right"></i>' + response.message + ' ('+response.code+')</div>', {
|
||||
pos: 'top-center',
|
||||
|
@ -58,10 +59,13 @@ jq(document).ready(function (jq) {
|
|||
}
|
||||
|
||||
}).fail(function(response, code, resp) {
|
||||
console.log(response);
|
||||
console.log(code);
|
||||
console.log(resp);
|
||||
contactModal.hide();
|
||||
resp = response;
|
||||
console.log(response);
|
||||
UIkit.notify('<i class="uk-icon uk-icon-frown-o uk-icon-justify uk-margin-right"></i>'+ response.message + ' ('+response.status+')</div>', {
|
||||
pos: 'top-center',
|
||||
status: 'danger'
|
||||
});
|
||||
}).done(function () {
|
||||
contactModal.hide();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue