-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathRestifizerError.cs
93 lines (74 loc) · 2.18 KB
/
RestifizerError.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using UnityEngine;
using System.Collections;
namespace Restifizer {
public class RestifizerError: System.Exception {
public int Status;
public Hashtable ErrorRaw;
public ArrayList ErrorListRaw;
public string Tag;
public RestifizerError(int status, object error, string tag) {
this.Status = status;
this.Tag = tag;
if (error is ArrayList) {
this.ErrorListRaw = (ArrayList)error;
} else if (error is Hashtable) {
this.ErrorRaw = (Hashtable)error;
} else if (error != null) {
Debug.LogWarning("Unsupported type in response: " + error.GetType());
}
parse();
}
virtual protected void parse() {
}
override public string ToString() {
string result = "tag: " + Tag + ", status: " + Status + ", raw: ";
if (ErrorRaw != null) {
result += ErrorRaw.ToString();
} else if (ErrorListRaw != null) {
result += ErrorListRaw.ToString();
} else {
result += "<EMPTY>";
}
return result;
}
}
public class BadRequestError: RestifizerError {
public BadRequestError(int status, object error, string tag): base(status, error, tag) {
}
protected override void parse() {
// TODO: Implement
}
}
public class UnauthorizedError: RestifizerError {
public new string Message;
public UnauthorizedError(int status, object error, string tag): base(status, error, tag) {
}
protected override void parse() {
Message = ErrorRaw["message"] as string;
}
}
public class ForbiddenError: RestifizerError {
public ForbiddenError(int status, object error, string tag): base(status, error, tag) {
}
protected override void parse() {
// TODO: Implement
}
}
public class NotFoundError: RestifizerError {
public NotFoundError(int status, object error, string tag): base(status, error, tag) {
}
protected override void parse() {
// TODO: Implement
}
}
public class ServerNotAvailableError: RestifizerError {
public ServerNotAvailableError(string tag): base(-1, null, tag) {
}
}
public class WrongResponseFormatError: RestifizerError {
public string UnparsedResponse;
public WrongResponseFormatError(object error, string tag): base(-2, null, tag) {
UnparsedResponse = error as string;
}
}
}