error-view #10

Merged
vivien.dufour merged 10 commits from error-view into master 1 year ago
Owner

Add an error view for error 404, 401 and 403

Add an error view for error 404, 401 and 403
vivien.dufour added 8 commits 1 year ago
maxime.batista approved these changes 1 year ago
public/index.php Outdated
$router->setBasePath($basePath);
$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig);
$errorController = new \App\Controller\ErrorController(new FormResultGateway($con), $twig);

No need to instanciate a this class here

No need to instanciate a this class here
vivien.dufour marked this conversation as resolved
class ErrorController
{
private FormResultGateway $gateway;

why use a gateway in something that only displays an error view ?
Moreover, it is not used anywhere in the class, you should remove it

why use a gateway in something that only displays an error view ? Moreover, it is not used anywhere in the class, you should remove it
vivien.dufour marked this conversation as resolved
/**
* @param FormResultGateway $gateway
*/
public function __construct(FormResultGateway $gateway, Environment $twig)

Remove the constructor, the $twig will be passed to the displayError function directly, and made static.

Remove the constructor, the `$twig` will be passed to the displayError function directly, and made static.
vivien.dufour marked this conversation as resolved
$this->twig = $twig;
}
public function displayError($error) {

As this class is an utilitary class that proposes functions to display an error view, you should make this function static, and add a new Environment: $twig parameter;

As this class is an utilitary class that proposes functions to display an error view, you should make this function static, and add a new `Environment: $twig` parameter;
vivien.dufour marked this conversation as resolved
public function displayError($error) {
$error = array("error" => $error);
try {
echo $this->twig->render('error.html.twig', $error);

You can use $this->twig->display instead of echoing the result of render :

- echo $this->twig->render('error.html.twig', $error);
+ $this->twig->display('error.html.twig', $error);
You can use $this->twig->display instead of echoing the result of render : ```diff - echo $this->twig->render('error.html.twig', $error); + $this->twig->display('error.html.twig', $error); ```
vivien.dufour marked this conversation as resolved
<meta charset="UTF-8">
<title>Error</title>
{% block stylesheets %}

useless block use, you should remove it

useless block use, you should remove it
vivien.dufour marked this conversation as resolved
h1 {
color: #da6110;
text-align: center;
margin-bottom: 15px}
-  		margin-top: 15px}
+		margin-top: 15px
+	}
```diff - margin-top: 15px} + margin-top: 15px + } ```
vivien.dufour marked this conversation as resolved
h2 {
text-align: center;
margin-bottom: 15px;
margin-top: 15px}
-  		margin-top: 15px}
+		margin-top: 15px
+	}
```diff - margin-top: 15px} + margin-top: 15px + } ```
vivien.dufour marked this conversation as resolved
<h2>Erreur 401 : vous devez vous authentifier afin d'accèder à cette page</h2>
{% elseif error == "403" %}
<h2>Erreur 403 : vous n'avez pas les autorisations nécessaires pour accèder à cette page</h2>
{% endif %}

This is not easily extensible, if we want to add more error codes and/or message, we will need to modify this file.
You can simply do something like that :

- {% if error == "404" %}
-     <h2>Erreur 404 : cette page n'existe pas</h2>
- {% elseif error == "401" %}
-     <h2>Erreur 401 : vous devez vous authentifier afin d'accèder à cette page</h2>
- {% elseif error == "403" %}
-     <h2>Erreur 403 : vous n'avez pas les autorisations nécessaires pour accèder à cette page</h2>
- {% endif %}
+ <h2>{{ error_type }} : {{ error_message }} </h2>

You'll then need to pass those two new variables to the view's argument :

$twig->display("error.html.twig", ["error_type" => $error_type, "error_message" => $error_message])
This is not easily extensible, if we want to add more error codes and/or message, we will need to modify this file. You can simply do something like that : ```diff - {% if error == "404" %} - <h2>Erreur 404 : cette page n'existe pas</h2> - {% elseif error == "401" %} - <h2>Erreur 401 : vous devez vous authentifier afin d'accèder à cette page</h2> - {% elseif error == "403" %} - <h2>Erreur 403 : vous n'avez pas les autorisations nécessaires pour accèder à cette page</h2> - {% endif %} + <h2>{{ error_type }} : {{ error_message }} </h2> ``` You'll then need to pass those two new variables to the view's argument : ```php $twig->display("error.html.twig", ["error_type" => $error_type, "error_message" => $error_message]) ```
vivien.dufour marked this conversation as resolved
maxime.batista requested review from maxime.batista 1 year ago
maxime.batista requested changes 1 year ago
maxime.batista left a comment

I meant to request changes, not to approve it*.

I meant to request changes, not to approve it*.
mael.daim approved these changes 1 year ago
vivien.dufour added 1 commit 1 year ago
vivien.dufour force-pushed error-view from 4e94522295 to 03945892df 1 year ago
maxime.batista approved these changes 1 year ago
maxime.batista left a comment

very good 👍

very good :+1:
vivien.dufour merged commit 4aa2bde233 into master 1 year ago
vivien.dufour deleted branch error-view 1 year ago
vivien.dufour referenced this issue from a commit 1 year ago

Reviewers

mael.daim approved these changes 1 year ago
maxime.batista approved these changes 1 year ago
continuous-integration/drone/push Build is passing
The pull request has been merged as 4aa2bde233.
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: IQBall/Application-Web#10
Loading…
There is no content yet.