OSDN Git Service

c570ead4ba3b4060092d19bbe56e8630d0d34298
[opentween/open-tween.git] / OpenTween / Api / DataModel / TwitterError.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2014 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
10 // any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
21
22 using System;
23 using System.Collections.Generic;
24 using System.Linq;
25 using System.Runtime.Serialization;
26 using System.Text;
27 using System.Threading.Tasks;
28
29 namespace OpenTween.Api.DataModel
30 {
31     // 参照: https://dev.twitter.com/docs/error-codes-responses
32
33     [DataContract]
34     public class TwitterError
35     {
36         [DataMember(Name = "errors")]
37         public TwitterErrorItem[] Errors { get; set; }
38
39         /// <exception cref="SerializationException"/>
40         public static TwitterError ParseJson(string json)
41             => MyCommon.CreateDataFromJson<TwitterError>(json);
42     }
43
44     [DataContract]
45     public class TwitterErrorItem
46     {
47         [DataMember(Name = "code")]
48         public TwitterErrorCode Code { get; set; }
49
50         [DataMember(Name = "message")]
51         public string Message { get; set; }
52
53         public override string ToString()
54         {
55             if (Enum.IsDefined(typeof(TwitterErrorCode), this.Code))
56                 return this.Code.ToString();
57             else
58                 return this.Message;
59         }
60     }
61
62     /// <summary>
63     /// Twitter API から返されるエラーコード
64     /// </summary>
65     public enum TwitterErrorCode
66     {
67         /// <summary>
68         /// 不正なリクエスト等によって認証を完了できない場合に発生する。大体クライアントのせい
69         /// </summary>
70         AuthError = 32,
71
72         /// <summary>
73         /// 指定されたリソースが存在しません。HTTP 404 と同等
74         /// </summary>
75         NotFound = 34,
76
77         /// <summary>
78         /// アカウントが凍結されています
79         /// </summary>
80         SuspendedAccount = 64,
81
82         /// <summary>
83         /// REST API v1 は星になりました
84         /// </summary>
85         APIv1Retired = 68,
86
87         /// <summary>
88         /// レートリミットに到達しました
89         /// </summary>
90         RateLimit = 88,
91
92         /// <summary>
93         /// アクセストークンが無効です。不正なトークンまたはユーザーによって失効されています
94         /// </summary>
95         InvalidToken = 89,
96
97         /// <summary>
98         /// SSLを使わずにAPIに接続することはできません
99         /// </summary>
100         SslIsRequired = 92,
101
102         /// <summary>
103         /// サーバーの過負荷によって一時的にアクセスできません
104         /// </summary>
105         OverCapacity = 130,
106
107         /// <summary>
108         /// サーバーの内部エラー
109         /// </summary>
110         InternalError = 131,
111
112         /// <summary>
113         /// oauth_timestamp の時刻が無効。クライアントかサーバーの時計が大幅にずれている
114         /// </summary>
115         TimestampOutOfRange = 135,
116
117         /// <summary>
118         /// ユーザーからブロックされている (公式ドキュメントに記述無し)
119         /// </summary>
120         Blocked = 136,
121
122         /// <summary>
123         /// 既にふぁぼっているツイートをふぁぼろうとした (公式ドキュメントに記述無し)
124         /// </summary>
125         AlreadyFavorited = 139,
126
127         /// <summary>
128         /// 存在しないステータスID
129         /// </summary>
130         StatusNotFound = 144,
131
132         /// <summary>
133         /// 投稿されたメッセージが重複しています
134         /// </summary>
135         /// <remarks>
136         /// “There was an error sending your message: Whoops! You already said that.”
137         /// /direct_messages/new.json で重複するDMを送信すると発生
138         /// </remarks>
139         DuplicateMessage = 151,
140
141         /// <summary>
142         /// フォローの追加が制限されています
143         /// </summary>
144         FollowLimit = 161,
145
146         /// <summary>
147         /// 非公開ユーザーのため閲覧できません
148         /// </summary>
149         Protected = 179,
150
151         /// <summary>
152         /// 一日当たりの投稿可能なツイート数の制限に達しました
153         /// </summary>
154         DailyLimitReached = 185,
155
156         /// <summary>
157         /// 投稿されたステータスが重複しています
158         /// </summary>
159         DuplicateStatus = 187,
160
161         /// <summary>
162         /// 認証が必要な API で認証データが含まれていない、または認証データが不正
163         /// </summary>
164         AuthenticationRequired = 215,
165
166         /// <summary>
167         /// スパムの疑いのあるリクエストがブロックされました
168         /// </summary>
169         RequestBlocked = 226,
170
171         /// <summary>
172         /// 廃止されたエンドポイント
173         /// </summary>
174         RetiredEndpoint = 251,
175
176         /// <summary>
177         /// アプリケーションの書き込み権限が規制されています
178         /// </summary>
179         AppWriteRestricted = 261,
180
181         /// <summary>
182         /// 自分自身をミュートに設定することはできません
183         /// </summary>
184         CantMuteYourself = 271,
185
186         /// <summary>
187         /// ミュート設定されていないユーザーをミュート解除しようとしています
188         /// </summary>
189         NotMuting = 272,
190
191         /// <summary>
192         /// 投稿されたDMが重複しています
193         /// </summary>
194         /// <remarks>
195         /// “Direct Message is a duplicate.”
196         /// /statuses/update.json に「D screen_name ...」形式で重複したDMを送信すると発生
197         /// </remarks>
198         DuplicateDM = 311,
199
200         /// <summary>
201         /// DMで投稿可能な文字数を超えています
202         /// </summary>
203         DMCharacterLimit = 354,
204     }
205 }