2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using Tizen.Internals.Errors;
20 namespace Tizen.Account.OAuth2
22 internal enum OAuth2Error
24 // Tizen Account Oauth Error
25 // TIZEN_ERROR_ACCOUNT_OAUTH -0x01010000
27 None = ErrorCode.None,
28 OutOfMemory = ErrorCode.OutOfMemory,
29 InvalidParameter = ErrorCode.InvalidParameter,
30 AlreadyInProgress = ErrorCode.AlreadyInProgress,
31 NotSupported = ErrorCode.NotSupported,
32 PermissionDenied = ErrorCode.PermissionDenied,
33 ParseFailed = -0x01010000 | 0X01,
34 NetworkError = -0x01010000 | 0X02,
35 Server = -0x01010000 | 0X03,
36 UserCancelled = -0x01010000 | 0X04,
37 ValueNotFound = -0x01010000 | 0X05,
38 Unknown = ErrorCode.Unknown
41 internal class ErrorFactory
43 internal static string LogTag = "Tizen.Account.OAuth2";
45 internal static Exception GetException(IntPtr error)
47 int serverErrorCode, platformErrorCode;
48 int ret = Interop.Error.GetCode(error, out serverErrorCode, out platformErrorCode);
49 if (ret != (int)OAuth2Error.None)
51 Log.Debug(ErrorFactory.LogTag, "error code can't be found");
54 string errorDescription;
55 ret = Interop.Error.GetDescription(error, out errorDescription);
56 if (ret != (int)OAuth2Error.None)
58 Log.Debug(ErrorFactory.LogTag, "error description can't be found");
62 Interop.Error.GetUri(error, out uri);
63 if (ret != (int)OAuth2Error.None)
65 Log.Debug(ErrorFactory.LogTag, "error uri can't be found");
68 var errorResponse = new OAuth2ErrorResponse()
70 PlatformErrorCode = platformErrorCode,
71 ServerErrorCode = serverErrorCode,
73 Error = errorDescription
76 return new OAuth2Exception() { Error = errorResponse };
79 internal static Exception GetException(int error)
81 if ((OAuth2Error)error == OAuth2Error.OutOfMemory)
83 return new OutOfMemoryException("Out of memory");
85 else if ((OAuth2Error)error == OAuth2Error.InvalidParameter)
87 return new ArgumentException("Invalid parameter");
89 else if ((OAuth2Error)error == OAuth2Error.AlreadyInProgress)
91 return new InvalidOperationException("Request already in progress");
93 else if ((OAuth2Error)error == OAuth2Error.NotSupported)
95 return new NotSupportedException("Not supported");
97 else if ((OAuth2Error)error == OAuth2Error.PermissionDenied)
99 return new UnauthorizedAccessException("Permission denied");
101 else if ((OAuth2Error)error == OAuth2Error.ParseFailed)
103 return new FormatException("Parsing failed");
105 else if ((OAuth2Error)error == OAuth2Error.NetworkError)
107 return new Exception("Networking error occured");
109 else if ((OAuth2Error)error == OAuth2Error.Server)
111 return new Exception("Server error");
113 else if ((OAuth2Error)error == OAuth2Error.UserCancelled)
115 return new Exception("User cancelled");
117 else if ((OAuth2Error)error == OAuth2Error.ValueNotFound)
119 return new ArgumentException("Value not found");
123 return new Exception("Unknown error");