Merge remote-tracking branch 'widget-viewer/tizen'
[platform/core/csapi/tizenfx.git] / src / Tizen.Messaging / Tizen.Messaging.Email / EmailErrorFactory.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.IO;
19 using Tizen.Internals.Errors;
20
21 namespace Tizen.Messaging.Email
22 {
23     internal enum EmailError
24     {
25         None = ErrorCode.None,
26         OutOfMemory = ErrorCode.OutOfMemory,
27         InvalidParameter = ErrorCode.InvalidParameter,
28         ServerNotReady = -0x01710000 | 0x501,
29         CommunicationWithServerFailed = -0x01710000 | 0x502,
30         OutOfRange = -0x01710000 | 0x503,
31         SendingFailed = -0x01710000 | 0x504,
32         OperationFailed = -0x01710000 | 0x505,
33         NoSimCard = -0x01710000 | 0x506,
34         NoData = -0x01710000 | 0x507,
35         PermissionDenied = ErrorCode.PermissionDenied,
36         NotSupported = ErrorCode.NotSupported
37     }
38
39     internal static class EmailErrorFactory
40     {
41         internal const string LogTag = "Tizen.Messaging.Email";
42
43         internal static Exception GetException(int err)
44         {
45             EmailError error = (EmailError)err;
46             if (error == EmailError.OutOfMemory)
47             {
48                 return new OutOfMemoryException("Out of memory");
49             }
50             else if (error == EmailError.InvalidParameter)
51             {
52                 return new ArgumentException("Invalid parameter");
53             }
54             else if (error == EmailError.ServerNotReady)
55             {
56                 return new IOException("Server not ready yet"); ;
57             }
58             else if (error == EmailError.NoData)
59             {
60                 return new InvalidDataException("No data found");
61             }
62             else if (error == EmailError.CommunicationWithServerFailed)
63             {
64                 return new TimeoutException("timed out");
65             }
66             else if (error == EmailError.PermissionDenied)
67             {
68                 return new UnauthorizedAccessException("Permission denied");
69             }
70             else if (error == EmailError.NotSupported)
71             {
72                 return new NotSupportedException("Not supported");
73             }
74             else if (error == EmailError.OutOfRange)
75             {
76                 return new IndexOutOfRangeException("Out of range");
77             }
78             else if (error == EmailError.SendingFailed)
79             {
80                 return new Exception("Sending failed");
81             }
82             else if (error == EmailError.OperationFailed)
83             {
84                 return new InvalidOperationException("operation failed");
85             }
86             else if (error == EmailError.NoSimCard)
87             {
88                 return new Exception("No sim card found");
89             }
90             else
91             {
92                 return new Exception("System operation");
93             }
94         }
95     }
96 }