Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.EC6.Convive.Controller;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

@Controller
public class CustomErrorController implements ErrorController {

@RequestMapping("/error")
public String handleError(HttpServletRequest request, Model model) {
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
Object message = request.getAttribute(RequestDispatcher.ERROR_MESSAGE);

String codigoErro = "ERR-" + UUID.randomUUID().toString().substring(0, 6).toUpperCase();
String dataHora = LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"));

if (status != null) {
codigoErro = "HTTP-" + status.toString();
}

model.addAttribute("codigoErro", codigoErro);
model.addAttribute("dataHora", dataHora);

String msgErro = (message != null && !message.toString().isBlank())
? message.toString()
: "Acesso negado, recurso não encontrado ou ocorreu um erro inesperado.";

model.addAttribute("mensagem", msgErro);

return "public/error";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public String handleException(Exception ex, Model model) {
System.err.println("[" + codigoErro + "] " + ex.getMessage());
ex.printStackTrace();

return "error";
return "public/error";
}
}
6 changes: 3 additions & 3 deletions Convive/src/main/resources/templates/morador/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ <h2 class="font-h2 text-h2 text-primary mb-xs">Próximas Reservas</h2>
</div>

</div>
<button class="w-full mt-2 py-sm bg-primary text-on-primary rounded-lg font-body-sm text-body-sm hover:bg-primary/90 transition-colors flex items-center justify-center gap-xs">
<span class="material-symbols-outlined text-[18px]" data-icon="add">add</span> Nova Reserva
</button>
<a th:href="@{/morador/ocorrencias}" class="w-full mt-2 py-sm bg-primary text-on-primary rounded-lg font-body-sm text-body-sm hover:bg-primary/90 transition-colors flex items-center justify-center gap-xs no-underline">
<span class="material-symbols-outlined text-[18px]" data-icon="add">add</span> Registrar Ocorrência
</a>
</aside>
</div>
</main>
Expand Down
Loading