1 package com.atlassian.marketplace.client.model;
2
3 import com.atlassian.fugue.Option;
4
5 /**
6 * Details of an error returned by the server.
7 * @since 2.0.0
8 */
9 public class ErrorDetail
10 {
11 String message;
12 Option<String> code;
13 Option<String> path;
14
15 /**
16 * The error message. For errors related to a specific request property, the message will
17 * normally be a fragment such as "required" or "cannot be zero" rather than a complete
18 * sentence; refer to {@link #getPath()} to see which property was involved.
19 */
20 public String getMessage()
21 {
22 return message;
23 }
24
25 /**
26 * The error code. If present, this string is a stable identifier for some specific type
27 * of error, which will not change even if the message text changes.
28 */
29 public Option<String> getCode()
30 {
31 return code;
32 }
33
34 /**
35 * The path to a request property that was involved in the error, if any. This uses
36 * JSON Pointer format, and refers to the JSON representation of the request: so, for
37 * instance, a top-level property called "name" would have a path of "/name", and the
38 * link URI of a "vendor" link would have a path of "/_links/vendor/href".
39 */
40 public Option<String> getPath()
41 {
42 return path;
43 }
44
45 @Override
46 public String toString()
47 {
48 for (String p: path)
49 {
50 return p + ": " + message;
51 }
52 return message;
53 }
54
55 @Override
56 public boolean equals(Object other)
57 {
58 if (other instanceof ErrorDetail)
59 {
60 ErrorDetail o = (ErrorDetail) other;
61 return message.equals(o.message) && code.equals(o.code) && path.equals(o.path);
62 }
63 return false;
64 }
65
66 @Override
67 public int hashCode()
68 {
69 return message.hashCode() + code.hashCode() + path.hashCode();
70 }
71 }