nginx: error pages are now respond as json if accept header request it.

As a consequence, we can rely on them to display a correct information on user pages through angularJS.
This commit is contained in:
nemunaire 2018-12-02 00:43:11 +01:00
parent cf290732dc
commit 63a55a8a0b
12 changed files with 103 additions and 27 deletions

View File

@ -35,4 +35,29 @@ server {
location /tags/ { location /tags/ {
rewrite ^/.*$ /index.html; rewrite ^/.*$ /index.html;
} }
location = /welcome.html {
internal;
if ($http_accept ~ "^application/json") {
rewrite ^/(.*).html$ /$1.json;
}
}
location = /e404.html {
internal;
if ($http_accept ~ "^application/json") {
rewrite ^/(.*).html$ /$1.json;
}
}
location = /e413.html {
internal;
if ($http_accept ~ "^application/json") {
rewrite ^/(.*).html$ /$1.json;
}
}
location = /e500.html {
internal;
if ($http_accept ~ "^application/json") {
rewrite ^/(.*).html$ /$1.json;
}
}
} }

View File

@ -22,6 +22,31 @@ server {
#auth_basic_user_file ficpasswd; #auth_basic_user_file ficpasswd;
} }
location = /welcome.html {
internal;
if ($http_accept ~ "^application/json") {
rewrite ^/(.*).html$ /$1.json;
}
}
location = /e404.html {
internal;
if ($http_accept ~ "^application/json") {
rewrite ^/(.*).html$ /$1.json;
}
}
location = /e413.html {
internal;
if ($http_accept ~ "^application/json") {
rewrite ^/(.*).html$ /$1.json;
}
}
location = /e500.html {
internal;
if ($http_accept ~ "^application/json") {
rewrite ^/(.*).html$ /$1.json;
}
}
location /edit { location /edit {
rewrite ^/.*$ /index.html; rewrite ^/.*$ /index.html;
} }

View File

@ -41,15 +41,27 @@ server {
} }
location = /welcome.html { location = /welcome.html {
internal; internal;
if ($http_accept ~ "^application/json") {
rewrite ^/(.*).html$ /$1.json;
}
} }
location = /e404.html { location = /e404.html {
internal; internal;
if ($http_accept ~ "^application/json") {
rewrite ^/(.*).html$ /$1.json;
}
} }
location = /e413.html { location = /e413.html {
internal; internal;
if ($http_accept ~ "^application/json") {
rewrite ^/(.*).html$ /$1.json;
}
} }
location = /e500.html { location = /e500.html {
internal; internal;
if ($http_accept ~ "^application/json") {
rewrite ^/(.*).html$ /$1.json;
}
} }
location ~ ^/[A-Z] { location ~ ^/[A-Z] {

View File

@ -10,6 +10,11 @@
<meta name="robots" content="all"> <meta name="robots" content="all">
<link href="/css/bootstrap.min.css" type="text/css" rel="stylesheet" media="screen"> <link href="/css/bootstrap.min.css" type="text/css" rel="stylesheet" media="screen">
<link href="/css/fic.css" type="text/css" rel="stylesheet" media="screen"> <link href="/css/fic.css" type="text/css" rel="stylesheet" media="screen">
<style>
.niceborder {
border-bottom-color: #ee5f5b;
}
</style>
</head> </head>
<body class="bg-light"> <body class="bg-light">
@ -30,7 +35,7 @@
</div> </div>
<div class="container" style="margin-top:20px;"> <div class="container" style="margin-top:20px;">
<div class="jumbotron"> <div class="jumbotron niceborder">
<h1>Page introuvable <small>Erreur 404</small></h1> <h1>Page introuvable <small>Erreur 404</small></h1>
<hr> <hr>
<p class="lead"> <p class="lead">

View File

@ -0,0 +1 @@
{"errmsg": "La page à laquelle vous tentez d'accéder n'existe pas ou l'adresse que vous avez tapée est incorrecte."}

View File

@ -10,6 +10,11 @@
<meta name="robots" content="all"> <meta name="robots" content="all">
<link href="/css/bootstrap.min.css" type="text/css" rel="stylesheet" media="screen"> <link href="/css/bootstrap.min.css" type="text/css" rel="stylesheet" media="screen">
<link href="/css/fic.css" type="text/css" rel="stylesheet" media="screen"> <link href="/css/fic.css" type="text/css" rel="stylesheet" media="screen">
<style>
.niceborder {
border-bottom-color: #ee5f5b;
}
</style>
</head> </head>
<body class="bg-light"> <body class="bg-light">
@ -30,7 +35,7 @@
</div> </div>
<div class="container" style="margin-top:20px;"> <div class="container" style="margin-top:20px;">
<div class="jumbotron"> <div class="jumbotron niceborder">
<h1>Requête trop grosse <small>Erreur 413</small></h1> <h1>Requête trop grosse <small>Erreur 413</small></h1>
<hr> <hr>
<p class="lead"> <p class="lead">

View File

@ -0,0 +1 @@
{"errmsg": "La quantité de données que vous souhaitez envoyer au serveur est trop importante pour qu'il accepte de la traiter."}

View File

@ -10,6 +10,11 @@
<meta name="robots" content="all"> <meta name="robots" content="all">
<link href="/css/bootstrap.min.css" type="text/css" rel="stylesheet" media="screen"> <link href="/css/bootstrap.min.css" type="text/css" rel="stylesheet" media="screen">
<link href="/css/fic.css" type="text/css" rel="stylesheet" media="screen"> <link href="/css/fic.css" type="text/css" rel="stylesheet" media="screen">
<style>
.niceborder {
border-bottom-color: #ee5f5b;
}
</style>
</head> </head>
<body class="bg-light"> <body class="bg-light">
@ -30,11 +35,11 @@
</div> </div>
<div class="container" style="margin-top:20px;"> <div class="container" style="margin-top:20px;">
<div class="jumbotron"> <div class="jumbotron niceborder">
<h1>Erreur interne <small>Erreur 500</small></h1> <h1>Erreur interne <small>Erreur 500</small></h1>
<hr> <hr>
<p class="lead"> <p class="lead">
Notre serveur est actuellement dans l'incapacit&eacute; de repondre &agrave; votre requ&ecirc;te.<br>Veuillez recommencer dans quelques instants. Notre serveur est actuellement dans l'incapacit&eacute; de r&eacute;pondre &agrave; votre requ&ecirc;te.<br>Veuillez recommencer dans quelques instants.
</p> </p>
<p> <p>
Si le problème persiste, <a href="mailto:root@srs.epita.fr">contactez un administrateur</a>. Si le problème persiste, <a href="mailto:root@srs.epita.fr">contactez un administrateur</a>.

View File

@ -0,0 +1 @@
{"errmsg": "Notre serveur est actuellement dans l'incapacité de répondre à votre requête. \nVeuillez recommencer dans quelques instants."}

View File

@ -293,17 +293,13 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
}; };
}) })
.controller("SubmissionController", function($scope, $http, $rootScope, $timeout) { .controller("SubmissionController", function($scope, $http, $rootScope, $timeout) {
$rootScope.sberr = ""; $scope.sberr = null;
var cbs; var cbs;
var cbd; var cbd;
$scope.$watch("my", function(my) { $scope.$watch("my", function(my) {
if (!my || !my.exercices || !my.exercices[$rootScope.current_exercice]) { if (my && my.exercices && my.exercices[$rootScope.current_exercice]) {
if (cbs)
$timeout.cancel(cbs);
cbs = $timeout(waitMy, 420);
} else {
angular.forEach(my.exercices[$rootScope.current_exercice].mcqs, function(mcq,qid) { angular.forEach(my.exercices[$rootScope.current_exercice].mcqs, function(mcq,qid) {
angular.forEach(mcq["choices"], function(choice,cid) { angular.forEach(mcq["choices"], function(choice,cid) {
this[cid] = { this[cid] = {
@ -322,6 +318,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$scope.ssubmit = function() { $scope.ssubmit = function() {
var resp = {} var resp = {}
var check = undefined var check = undefined
$scope.sberr = null;
if ($scope.my.exercices[$rootScope.current_exercice].flags && Object.keys($scope.my.exercices[$rootScope.current_exercice].flags).length) if ($scope.my.exercices[$rootScope.current_exercice].flags && Object.keys($scope.my.exercices[$rootScope.current_exercice].flags).length)
{ {
@ -384,10 +381,10 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
return; return;
} }
$http({ url: "/submit/" + $rootScope.current_exercice, method: "POST", data: resp }).then(function(response, status, header, config) { $http({ url: "/submit/" + $rootScope.current_exercice, method: "POST", data: resp }).then(function(response) {
$rootScope.messageClass = {"text-success": true}; $scope.messageClass = {"text-success": true};
$rootScope.message = response.data.errmsg; $scope.message = response.data.errmsg;
$rootScope.sberr = ""; $scope.sberr = null;
angular.forEach($scope.flags, function(flag,kid) { angular.forEach($scope.flags, function(flag,kid) {
flag.value = ""; flag.value = "";
@ -407,15 +404,13 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
}); });
}; };
checkDiff(); checkDiff();
}, function(response, status, header, config) { }, function(response) {
if (status >= 500) { if (response.status >= 500) {
$scope.my.exercices[$rootScope.current_exercice].submitted = false; $scope.my.exercices[$rootScope.current_exercice].submitted = false;
} }
$rootScope.messageClass = {"text-danger": true}; $scope.messageClass = {"text-danger": true};
$rootScope.message = response.data.errmsg; $scope.sberr = "Oups !";
if (status != 402) { $scope.message = response.data.errmsg;
$rootScope.sberr = "Une erreur est survenue lors de l'envoi. Veuillez réessayer dans quelques instants.";
}
}); });
$scope.my.exercices[$rootScope.current_exercice].submitted = true; $scope.my.exercices[$rootScope.current_exercice].submitted = true;
}; };

View File

@ -30,7 +30,7 @@
</div> </div>
<div class="container text-justify" style="margin-top:20px; text-indent: 1.5em"> <div class="container text-justify" style="margin-top:20px; text-indent: 1.5em">
<div class="jumbotron"> <div class="jumbotron niceborder">
<h1 style="text-indent: 0">Bienvenue !</h1> <h1 style="text-indent: 0">Bienvenue !</h1>
<p style="text-indent: 0" class="alert alert-primary"> <p style="text-indent: 0" class="alert alert-primary">
<strong> <strong>
@ -50,7 +50,7 @@
</p> </p>
</div> </div>
<div class="card" style="margin-bottom:20px;"> <div class="card niceborder" style="margin-bottom:20px;">
<div class="card-header bg-dark"> <div class="card-header bg-dark">
<h2 style="margin: 0">Installation du certificat client</h2> <h2 style="margin: 0">Installation du certificat client</h2>
</div> </div>
@ -92,7 +92,7 @@
</div> </div>
</div> </div>
<div class="card" style="margin-bottom:20px;"> <div class="card niceborder" style="margin-bottom:20px;">
<div class="card-header bg-dark"> <div class="card-header bg-dark">
<h2 id="cert-client-mozilla-firefox" style="margin: 0">Mozilla Firefox</h2> <h2 id="cert-client-mozilla-firefox" style="margin: 0">Mozilla Firefox</h2>
</div> </div>
@ -109,7 +109,7 @@
</div> </div>
</div> </div>
<div class="card" style="margin-bottom:20px;"> <div class="card niceborder" style="margin-bottom:20px;">
<div class="card-header bg-dark"> <div class="card-header bg-dark">
<h2 id="cert-client-chromium" style="margin: 0">Chromium/Google Chrome</h2> <h2 id="cert-client-chromium" style="margin: 0">Chromium/Google Chrome</h2>
</div> </div>
@ -141,7 +141,7 @@
</div> </div>
</div> </div>
<div class="card" style="margin-bottom:20px;"> <div class="card niceborder" style="margin-bottom:20px;">
<div class="card-header bg-dark"> <div class="card-header bg-dark">
<h2 id="cert-client-ie" style="margin: 0">Internet Explorer</h2> <h2 id="cert-client-ie" style="margin: 0">Internet Explorer</h2>
</div> </div>
@ -168,7 +168,7 @@
</div> </div>
</div> </div>
<div class="card" style="margin-bottom:20px;"> <div class="card niceborder" style="margin-bottom:20px;">
<div class="card-header bg-dark"> <div class="card-header bg-dark">
<h2 id="cert-client-safari" style="margin: 0">Safari</h2> <h2 id="cert-client-safari" style="margin: 0">Safari</h2>
</div> </div>

View File

@ -0,0 +1 @@
{"errmsg": "Vous n'avez pas les droits nécessaires pour effectuer cette action."}