package com.fp.frontend.controller.error;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

@ManagedBean
@RequestScoped
public class ErrorController {

    private String statusCode;
    private String errorMessage;
    private HttpServletRequest request;

    public ErrorController() {
        FacesContext fc = FacesContext.getCurrentInstance();
        this.request = ((HttpServletRequest) fc.getExternalContext().getRequest());
    }

    public HttpServletRequest getRequest() {
        return this.request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    public String getStatusCode() {
        this.statusCode = this.request.getAttribute("javax.servlet.error.status_code").toString();
        return this.statusCode;
    }

    public void setStatusCode(String statusCode) {
        this.statusCode = statusCode;
    }

    public String getErrorMessage() {
        this.errorMessage = this.request.getAttribute("javax.servlet.error.message").toString();
        return this.errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

}
