package com.codenetworkz.portfoliowebsite.controllers;

import com.codenetworkz.portfoliowebsite.exceptions.InternalServerException;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(InternalServerException.class)
    public String handleInternalServerException(InternalServerException ex, Model model) {
        model.addAttribute("errorMessage", ex.getMessage());
        model.addAttribute("errorCode", 500);
        return "error"; // Name of the Thymeleaf template
    }

}
