1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.jira.rest.client.api;
18
19 import com.atlassian.jira.rest.client.api.domain.util.ErrorCollection;
20 import com.google.common.base.Optional;
21 import com.google.common.collect.ImmutableList;
22
23 import java.util.Collection;
24 import java.util.Collections;
25
26
27
28
29
30
31
32 public class RestClientException extends RuntimeException {
33
34 private final Optional<Integer> statusCode;
35 private final Collection<ErrorCollection> errorCollections;
36
37 public RestClientException(final RestClientException exception) {
38 super(exception.getMessage(), exception);
39 this.statusCode = exception.getStatusCode();
40 this.errorCollections = exception.errorCollections;
41 }
42
43 public RestClientException(final Throwable cause) {
44 super(cause);
45 this.errorCollections = Collections.emptyList();
46 this.statusCode = Optional.absent();
47 }
48
49 public RestClientException(final Throwable cause, final int statusCode) {
50 super(cause);
51 this.errorCollections = Collections.emptyList();
52 this.statusCode = Optional.of(statusCode);
53 }
54
55 public RestClientException(final String errorMessage, final Throwable cause) {
56 super(errorMessage, cause);
57 this.errorCollections = ImmutableList.of(new ErrorCollection(errorMessage));
58 statusCode = Optional.absent();
59 }
60
61 public RestClientException(final Collection<ErrorCollection> errorCollections, final int statusCode) {
62 super(errorCollections.toString());
63 this.errorCollections = ImmutableList.copyOf(errorCollections);
64 this.statusCode = Optional.of(statusCode);
65 }
66
67 public RestClientException(final Collection<ErrorCollection> errorCollections, final Throwable cause, final int statusCode) {
68 super(errorCollections.toString(), cause);
69 this.errorCollections = ImmutableList.copyOf(errorCollections);
70 this.statusCode = Optional.of(statusCode);
71 }
72
73
74
75
76 public Collection<ErrorCollection> getErrorCollections() {
77 return errorCollections;
78 }
79
80
81
82
83 public Optional<Integer> getStatusCode() {
84 return statusCode;
85 }
86
87 @Override
88 public String toString() {
89 return "RestClientException{" +
90 "statusCode=" + statusCode +
91 ", errorCollections=" + errorCollections +
92 '}';
93 }
94 }