blob: 9e615f303f4b5a37b9235f3842577b9d70f5cba7 [file] [log] [blame]
Michael Hanl8ee31112016-07-21 14:10:24 +02001package de.ids_mannheim.korap.exceptions;
2
3import de.ids_mannheim.korap.auditing.AuditRecord;
4import lombok.AccessLevel;
5import lombok.Getter;
6import lombok.Setter;
7import org.slf4j.Logger;
8import org.slf4j.LoggerFactory;
9
10import java.util.ArrayList;
11import java.util.Arrays;
12import 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)
22public 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}