| Michael Hanl | 8ee3111 | 2016-07-21 14:10:24 +0200 | [diff] [blame] | 1 | package de.ids_mannheim.korap.exceptions; |
| 2 | |
| 3 | import de.ids_mannheim.korap.auditing.AuditRecord; |
| 4 | import lombok.AccessLevel; |
| 5 | import lombok.Getter; |
| 6 | import lombok.Setter; |
| 7 | import org.slf4j.Logger; |
| 8 | import org.slf4j.LoggerFactory; |
| 9 | |
| 10 | import java.util.ArrayList; |
| 11 | import java.util.Arrays; |
| 12 | import java.util.List; |
| 13 | |
| 14 | /** |
| 15 | * @author hanl |
| 16 | * @date 08/04/2015 |
| 17 | */ |
| 18 | // should be a http exception that responds to a service point |
| 19 | // is the extension of the notauthorized exception! |
| 20 | @Setter(AccessLevel.PROTECTED) |
| 21 | @Getter(AccessLevel.PROTECTED) |
| 22 | public class ServiceException extends Exception { |
| 23 | |
| 24 | protected List<AuditRecord> records = new ArrayList<>(); |
| 25 | private static final Logger jlog = LoggerFactory |
| 26 | .getLogger(ServiceException.class); |
| 27 | |
| 28 | private int status; |
| 29 | private String entity; |
| 30 | private Object userid; |
| 31 | |
| 32 | |
| 33 | protected ServiceException (Object userid, Integer status, String message, |
| 34 | String args) { |
| 35 | super(message); |
| 36 | this.userid = userid; |
| 37 | this.status = status; |
| 38 | this.entity = args; |
| 39 | AuditRecord record = AuditRecord.serviceRecord(userid, status, args); |
| 40 | this.records.add(record); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | @Deprecated |
| 45 | public ServiceException (Object userid, Integer status, String ... args) { |
| 46 | this(userid, status, StatusCodes.getMessage(status), Arrays |
| 47 | .asList(args).toString()); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | public ServiceException (Integer status, KustvaktException ex) { |
| 52 | this(ex.getUserid(), ex.getStatusCode(), ex.getMessage(), ex |
| 53 | .getEntity()); |
| 54 | AuditRecord record = AuditRecord.serviceRecord(ex.getUserid(), status, |
| 55 | ex.getEntity()); |
| 56 | record.setField_1(ex.toString()); |
| 57 | this.records.add(record); |
| 58 | jlog.error("Exception: " + ex.toString()); |
| 59 | } |
| 60 | |
| 61 | } |