io.toffees.exception.ErrorMessage.java Source code

Java tutorial

Introduction

Here is the source code for io.toffees.exception.ErrorMessage.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package io.toffees.exception;

import java.lang.reflect.InvocationTargetException;

import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Response;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

//import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.BeanUtils;

/*
*
* @author ptsilopoulos
*/
@XmlRootElement
public class ErrorMessage {

    /** contains the same HTTP Status code returned by the server */
    @XmlElement(name = "status")
    int status;

    /** application specific error code */
    @XmlElement(name = "code")
    int code;

    /** message describing the error*/
    @XmlElement(name = "message")
    String message;

    /** link point to page where the error message is documented */
    @XmlElement(name = "link")
    String link;

    /** extra information that might useful for developers */
    @XmlElement(name = "developerMessage")
    String developerMessage;

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getDeveloperMessage() {
        return developerMessage;
    }

    public void setDeveloperMessage(String developerMessage) {
        this.developerMessage = developerMessage;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public ErrorMessage(AppException ex) {
        // TO-DO should(?) use a try-catch clause in case it doesn't work BUT I can't make those compile
        BeanUtils.copyProperties(this, ex);
    }

    public ErrorMessage(NotFoundException ex) {
        this.status = Response.Status.NOT_FOUND.getStatusCode();
        this.message = ex.getMessage();
        this.link = "https://jersey.java.net/apidocs/2.8/jersey/javax/ws/rs/NotFoundException.html";
    }

    public ErrorMessage() {
    }
}