Summary Table

Categories Total Count
PII 0
URL 0
DNS 0
EKL 0
IP 0
PORT 0
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

package gov.va.med.pbm.ampl.exception;

import java.util.Arrays;
import java.util.Collection;

import org.springframework.http.HttpStatus;

/**
* The ApiError class handles any errors that may occur and assigns the HttpStatus appropriately.
*
* @author Ian Meinert
* @since 1.0
*/
public class ApiError {

private HttpStatus status;

private String message;

private Collection<String> errors;

/**
* The ApiError constructor which accepts an {@link HttpStatus}, message and Collection of errors.
*
* @param status the {@link HttpStatus} code
* @param message the error message associated with exception
* @param errors List of constructed error messages
*/
public ApiError(HttpStatus status, String message, Collection<String> errors) {
this.status = status;
this.message = message;
this.errors = errors;
}

/**
* The ApiError constructor which accepts an {@link HttpStatus}, message and an error.
*
* @param status the {@link HttpStatus} code
* @param message the error message associated with exception
* @param error the error constructed message
*/
public ApiError(HttpStatus status, String message, String error) {
this.status = status;
this.message = message;
this.errors = Arrays.asList(error);
}

/**
* The getter for the HttpStatus.
*
*
* @return The headers HttpStatus
*/
public HttpStatus getStatus() {
return status;
}

/**
* The setter for the HttpStatus.
*
* @param status the HttpStatus
*
*/
public void setStatus(HttpStatus status) {
this.status = status;
}

/**
* The getter for the Collection of errors.
*
*
* @return Collection of String
*/
public Collection<String> getErrors() {
return errors;
}

/**
* The setter for the Collection of errors.
*
* @param errors The Collection of errors
*
*/
public void setErrors(Collection<String> errors) {
this.errors = errors;
}

/**
* The getter for the message.
*
*
* @return error message
*/
public String getMessage() {
return message;
}

/**
* The setter for the message.
*
* @param message the error message
*
*/
public void setMessage(String message) {
this.message = message;
}

/**
* This method generates the class in a readable String format.
*
* @return descriptive version of the class properties and values.
*/
@Override
public String toString() {
String result = getStatus() + "," + getMessage() + "," + Arrays.toString(getErrors().toArray());

return result;
}
}