Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Notification / Tizen.Applications.Notifications / NotificationErrorFactory.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 namespace Tizen.Applications.Notifications
18 {
19     using System;
20     using System.Runtime.CompilerServices;
21
22     internal enum NotificationError
23     {
24         None = Tizen.Internals.Errors.ErrorCode.None,
25         InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
26         OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
27         IoError = Tizen.Internals.Errors.ErrorCode.IoError,
28         DbError = -0x01140000 | 0x01,
29         AlreadyExists = -0x01140000 | 0x02,
30         DBusError = -0x01140000 | 0x03,
31         DoesnotExist = -0x01140000 | 0x04,
32         ServiceError = -0x01140000 | 0x05,
33         PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
34         InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation
35     }
36
37     internal static class NotificationErrorFactory
38     {
39         internal static Exception GetException(NotificationError ret, string msg, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
40         {
41             Log.Error(Notification.LogTag, memberName + " : " + lineNumber);
42
43             switch (ret)
44             {
45                 case NotificationError.InvalidParameter:
46                     Log.Error(Notification.LogTag, msg);
47                     return new ArgumentException(ret + " error occurred.");
48                 case NotificationError.PermissionDenied:
49                     throw new UnauthorizedAccessException("Permission denied (http://tizen.org/privilege/notification)");
50                 default:
51                     Log.Error(Notification.LogTag, msg);
52                     return new InvalidOperationException(ret + " error occurred.");
53             }
54         }
55     }
56 }