Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOD-793] feat: HTML static page for error responses #17

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>woff</nonFilteredFileExtension>
<nonFilteredFileExtension>woff2</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>

<!-- Plugin required to build java classes from XSD using CXF -->
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import it.gov.pagopa.wispconverter.controller.model.RedirectResponse;
import it.gov.pagopa.wispconverter.exception.AppErrorCodeMessageEnum;
import it.gov.pagopa.wispconverter.exception.AppException;
import it.gov.pagopa.wispconverter.service.ConverterService;
Expand All @@ -22,20 +21,14 @@
import org.slf4j.MDC;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.MediaType;
import org.springframework.http.ProblemDetail;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.ErrorResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.Instant;
import java.util.Map;

@Controller
@RequestMapping
@Validated
Expand All @@ -58,18 +51,15 @@ public class RedirectController {
public String redirect(@Parameter(description = "", example = "identificativoIntermediarioPA_sessionId")
@NotBlank(message = "{redirect.session-id.not-blank}")
@RequestParam("sessionId") String sessionId,
Model model, HttpServletResponse response) {
HttpServletResponse response) {
try {
String redirectURI = converterService.convert(sessionId);
return "redirect:" + redirectURI;
} catch (AppException appException) {
ErrorResponse errorResponse = errorUtil.forAppException(appException);
ProblemDetail problemDetail = errorResponse.updateAndGetBody(this.messageSource, LocaleContextHolder.getLocale());
errorUtil.finalizeError(problemDetail, errorResponse.getStatusCode().value());

response.setStatus(errorResponse.getStatusCode().value());
model.addAttribute("sessionId", sessionId);
enrichModelWithError(model, problemDetail, errorResponse.getStatusCode().value());
response.setStatus(200);
return "error";
} catch (Exception ex) {
String operationId = MDC.get(Constants.MDC_OPERATION_ID);
Expand All @@ -79,52 +69,9 @@ public String redirect(@Parameter(description = "", example = "identificativoInt
ErrorResponse errorResponse = errorUtil.forAppException(appException);
ProblemDetail problemDetail = errorResponse.updateAndGetBody(this.messageSource, LocaleContextHolder.getLocale());
errorUtil.finalizeError(problemDetail, errorResponse.getStatusCode().value());

response.setStatus(errorResponse.getStatusCode().value());
model.addAttribute("sessionId", sessionId);
enrichModelWithError(model, problemDetail, errorResponse.getStatusCode().value());
response.setStatus(200);
return "error";
}

}


@Operation(summary = "", description = "", security = {@SecurityRequirement(name = "ApiKey")}, tags = {"Redirect"})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Redirect info to Checkout service.", content = @Content(schema = @Schema(implementation = RedirectResponse.class)))
})
@GetMapping(value = "/redirect", consumes = MediaType.APPLICATION_JSON_VALUE)
@TraceReEvent(businessProcess = BO_REDIRECT)
public ResponseEntity<RedirectResponse> redirectInfo(@Parameter(description = "", example = "identificativoIntermediarioPA_sessionId")
@NotBlank(message = "{redirect.session-id.not-blank}")
@RequestParam("sessionId") String sessionId) {
String redirectURI = converterService.convert(sessionId);
return ResponseEntity.ok(RedirectResponse.builder().redirectUrl(redirectURI).build());
}

private void enrichModelWithError(Model model, ProblemDetail problemDetail, int statusCode) {
model.addAttribute("type", problemDetail.getType());
model.addAttribute("title", problemDetail.getTitle());
model.addAttribute("status", statusCode);
model.addAttribute("detail", problemDetail.getDetail());

Map<String, Object> properties = problemDetail.getProperties();
if (properties != null) {
Instant timestamp = (Instant) properties.get(ErrorUtil.EXTRA_FIELD_ERROR_TIMESTAMP);
if (timestamp != null) {
model.addAttribute("timestamp", timestamp.toString());
}

String errrCode = (String) properties.get(ErrorUtil.EXTRA_FIELD_ERROR_CODE);
if (errrCode != null) {
model.addAttribute("errorCode", errrCode);
}

String operationId = (String) properties.get(ErrorUtil.EXTRA_FIELD_OPERATION_ID);
if (operationId != null) {
model.addAttribute("operationId", operationId);
}
}
}

}
Binary file added src/main/resources/static/images/error-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
104 changes: 104 additions & 0 deletions src/main/resources/static/style/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
@font-face {
font-family: 'Titillium Web';
font-weight: normal;
font-style: normal;
font-weight: 700;
src: url('font/titillium-web-latin-ext-700-normal.woff2') format('woff2'), url('font/titillium-web-all-700-normal.woff') format('woff');
}
@font-face {
font-family: 'Titillium Web';
font-style: normal;
font-display: swap;
font-weight: 700;
src: url('font/titillium-web-latin-700-normal.woff2') format('woff2'), url('font/titillium-web-all-700-normal.woff') format('woff');
unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
font-family: 'Titillium Web';
font-weight: normal;
font-style: normal;
font-weight: 400;
src: url('font/titillium-web-latin-ext-400-normal.woff2') format('woff2'), url('font/titillium-web-all-400-normal.woff') format('woff');
}
@font-face {
font-family: 'Titillium Web';
font-style: normal;
font-display: swap;
font-weight: 400;
src: url('font/titillium-web-latin-400-normal.woff2') format('woff2'), url('font/titillium-web-all-400-normal.woff') format('woff');
unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

.main-div {
/* Auto layout */
display: flex;
flex-direction: column;
top: 250px;
}

/* Title */
.error-title {
/*width: 376px;
height: 32px;*/
font-family: 'Titillium Web';
font-style: normal;
font-weight: 700;
font-size: 24px;
margin-top: 32px;
margin-bottom: 32px;
text-align: center;
color: #17324D;
flex: none;
order: 0;
flex-grow: 0;
}

/* Subtitle */
.error-subtitle {
/*width: 376px;
height: 24px;*/
font-family: 'Titillium Web';
font-style: normal;
font-weight: 400;
font-size: 16px;
line-height: 24px;
text-align: center;
letter-spacing: 0.15px;
color: #17324D;
flex: none;
order: 1;
flex-grow: 0;
}

/* Button */
.button {
font-family: 'Titillium Web';
box-sizing: border-box;
color: #0073E6;
font-weight: 700;
background-color: white;
padding: 0px;
width: 330px;
height: 40px;
border: 2px solid #0073E6;
border-radius: 4px;
flex: none;
order: 1;
flex-grow: 0;
}

/* Icon */
.error-icon {
width: 80px;
height: 80px;
flex: none;
order: 0;
flex-grow: 0;
}

body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
margin: 0;
}

52 changes: 30 additions & 22 deletions src/main/resources/templates/error.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Error</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Something went wrong! </h1>
<h2>Our Engineers are on it</h2>
<html lang="it" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta content="ie=edge" http-equiv="x-ua-compatible">
<title>Errore</title>
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel="stylesheet" th:href="@{/style/main.css}"/>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row justify-content-center align-items-center">
<div class="col-lg-3"></div>
<div class="col-lg-6 main-div">
<div class="text-center">
<img alt="Error icon" class="error-icon mx-auto" th:src="@{images/error-icon.png}">
</div>
<div class="text-center">
<h2 class="error-title">Si &egrave; verificato un errore imprevisto</h2>
<p class="error-subtitle">Riprova, oppure contatta l'assistenza</p>
<button class="button">Contatta l'assistenza</button>
</div>
</div>
<div class="col-lg-3"></div>
</div>
</div>

<div th:text="${sessionId}"></div>
<div th:text="${type}"></div>
<div th:text="${title}"></div>
<div th:text="${status}"></div>
<div th:text="${detail}"></div>
<div th:text="${timestamp}"></div>
<div th:text="${operationId}"></div>
<div th:text="${errorCode}"></div>


<a href="/">Go Home</a>
</body>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>

Check warning

Code scanning / CodeQL

Inclusion of functionality from an untrusted source Medium

Script loaded from content delivery network with no integrity check.
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
Loading