• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "js_err_utils.h"
17 
18 #include <map>
19 
20 namespace OHOS::Rosen {
21 constexpr const char* WM_ERROR_MSG_OK = "ok";
22 constexpr const char* WM_ERROR_MSG_DO_NOTHING = "do nothing";
23 constexpr const char* WM_ERROR_MSG_NO_MEM = "no mem";
24 constexpr const char* WM_ERROR_MSG_DESTROYED_OBJECT = "destroyed object";
25 constexpr const char* WM_ERROR_MSG_INVALID_WINDOW = "invalid window";
26 constexpr const char* WM_ERROR_MSG_INVALID_WINDOW_MODE_OR_SIZE = "invalid window mode or size";
27 constexpr const char* WM_ERROR_MSG_INVALID_OPERATION = "invalid operation";
28 constexpr const char* WM_ERROR_MSG_INVALID_PERMISSION = "invalid permission";
29 constexpr const char* WM_ERROR_MSG_NOT_SYSTEM_APP = "not system app";
30 constexpr const char* WM_ERROR_MSG_NO_REMOTE_ANIMATION = "no remote animation";
31 constexpr const char* WM_ERROR_MSG_INVALID_DISPLAY = "invalid display";
32 constexpr const char* WM_ERROR_MSG_INVALID_PARENT = "invalid parent";
33 constexpr const char* WM_ERROR_MSG_INVALID_OP_IN_CUR_STATUS = "invalid operation in the current window status";
34 constexpr const char* WM_ERROR_MSG_REPEAT_OPERATION = "repeat operation";
35 constexpr const char* WM_ERROR_MSG_INVALID_SESSION = "invalid session";
36 constexpr const char* WM_ERROR_MSG_INVALID_CALLING = "invalid calling";
37 constexpr const char* WM_ERROR_MSG_DEVICE_NOT_SUPPORT = "device not support";
38 constexpr const char* WM_ERROR_MSG_NEED_REPORT_BASE = "need report base";
39 constexpr const char* WM_ERROR_MSG_NULLPTR = "nullptr";
40 constexpr const char* WM_ERROR_MSG_INVALID_TYPE = "invalid type";
41 constexpr const char* WM_ERROR_MSG_INVALID_PARAM = "invalid param";
42 constexpr const char* WM_ERROR_MSG_SAMGR = "samgr";
43 constexpr const char* WM_ERROR_MSG_IPC_FAILED = "ipc failed";
44 constexpr const char* WM_ERROR_MSG_NEED_REPORT_END = "need report end";
45 constexpr const char* WM_ERROR_MSG_START_ABILITY_FAILED = "start ability failed";
46 constexpr const char* WM_ERROR_MSG_PIP_DESTROY_FAILED = "pip destroy failed";
47 constexpr const char* WM_ERROR_MSG_PIP_STATE_ABNORMALLY = "pip state abnormally";
48 constexpr const char* WM_ERROR_MSG_PIP_CREATE_FAILED = "pip create failed";
49 constexpr const char* WM_ERROR_MSG_PIP_INTERNAL_ERROR = "pip internal error";
50 constexpr const char* WM_ERROR_MSG_PIP_REPEAT_OPERATION = "pip repeat operation";
51 constexpr const char* WM_ERROR_MSG_ILLEGAL_PARAM = "parameter validation error";
52 constexpr const char* WM_ERROR_MSG_UI_EFFECT_ERROR = "Incorrect filter calling";
53 constexpr const char* WM_ERROR_MSG_TIMEOUT = "API call timed out";
54 
55 static std::map<WMError, const char*> WM_ERROR_TO_ERROR_MSG_MAP {
56     {WMError::WM_OK,                                    WM_ERROR_MSG_OK                          },
57     {WMError::WM_DO_NOTHING,                            WM_ERROR_MSG_DO_NOTHING                  },
58     {WMError::WM_ERROR_NO_MEM,                          WM_ERROR_MSG_NO_MEM                      },
59     {WMError::WM_ERROR_DESTROYED_OBJECT,                WM_ERROR_MSG_DESTROYED_OBJECT            },
60     {WMError::WM_ERROR_INVALID_WINDOW,                  WM_ERROR_MSG_INVALID_WINDOW              },
61     {WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE,     WM_ERROR_MSG_INVALID_WINDOW_MODE_OR_SIZE },
62     {WMError::WM_ERROR_INVALID_OPERATION,               WM_ERROR_MSG_INVALID_OPERATION           },
63     {WMError::WM_ERROR_INVALID_PERMISSION,              WM_ERROR_MSG_INVALID_PERMISSION          },
64     {WMError::WM_ERROR_NOT_SYSTEM_APP,                  WM_ERROR_MSG_NOT_SYSTEM_APP              },
65     {WMError::WM_ERROR_NO_REMOTE_ANIMATION,             WM_ERROR_MSG_NO_REMOTE_ANIMATION         },
66     {WMError::WM_ERROR_INVALID_DISPLAY,                 WM_ERROR_MSG_INVALID_DISPLAY             },
67     {WMError::WM_ERROR_INVALID_PARENT,                  WM_ERROR_MSG_INVALID_PARENT              },
68     {WMError::WM_ERROR_INVALID_OP_IN_CUR_STATUS,        WM_ERROR_MSG_INVALID_OP_IN_CUR_STATUS    },
69     {WMError::WM_ERROR_REPEAT_OPERATION,                WM_ERROR_MSG_REPEAT_OPERATION            },
70     {WMError::WM_ERROR_INVALID_SESSION,                 WM_ERROR_MSG_INVALID_SESSION             },
71     {WMError::WM_ERROR_INVALID_CALLING,                 WM_ERROR_MSG_INVALID_CALLING             },
72     {WMError::WM_ERROR_DEVICE_NOT_SUPPORT,              WM_ERROR_MSG_DEVICE_NOT_SUPPORT          },
73     {WMError::WM_ERROR_NEED_REPORT_BASE,                WM_ERROR_MSG_NEED_REPORT_BASE            },
74     {WMError::WM_ERROR_NULLPTR,                         WM_ERROR_MSG_NULLPTR                     },
75     {WMError::WM_ERROR_INVALID_TYPE,                    WM_ERROR_MSG_INVALID_TYPE                },
76     {WMError::WM_ERROR_INVALID_PARAM,                   WM_ERROR_MSG_INVALID_PARAM               },
77     {WMError::WM_ERROR_SAMGR,                           WM_ERROR_MSG_SAMGR                       },
78     {WMError::WM_ERROR_IPC_FAILED,                      WM_ERROR_MSG_IPC_FAILED                  },
79     {WMError::WM_ERROR_NEED_REPORT_END,                 WM_ERROR_MSG_NEED_REPORT_END             },
80     {WMError::WM_ERROR_START_ABILITY_FAILED,            WM_ERROR_MSG_START_ABILITY_FAILED        },
81     {WMError::WM_ERROR_PIP_DESTROY_FAILED,              WM_ERROR_MSG_PIP_DESTROY_FAILED          },
82     {WMError::WM_ERROR_PIP_STATE_ABNORMALLY,            WM_ERROR_MSG_PIP_STATE_ABNORMALLY        },
83     {WMError::WM_ERROR_PIP_CREATE_FAILED,               WM_ERROR_MSG_PIP_CREATE_FAILED           },
84     {WMError::WM_ERROR_PIP_INTERNAL_ERROR,              WM_ERROR_MSG_PIP_INTERNAL_ERROR          },
85     {WMError::WM_ERROR_PIP_REPEAT_OPERATION,            WM_ERROR_MSG_PIP_REPEAT_OPERATION        },
86     {WMError::WM_ERROR_ILLEGAL_PARAM,                   WM_ERROR_MSG_ILLEGAL_PARAM               },
87     {WMError::WM_ERROR_UI_EFFECT_ERROR,                 WM_ERROR_MSG_UI_EFFECT_ERROR             },
88     {WMError::WM_ERROR_TIMEOUT,                         WM_ERROR_MSG_TIMEOUT                     },
89 };
90 
91 constexpr const char* WM_ERROR_CODE_MSG_OK = "ok";
92 constexpr const char* WM_ERROR_CODE_MSG_NO_PERMISSION = "Permission verification failed. "
93     "The application does not have the permission required to call the API.";
94 constexpr const char* WM_ERROR_CODE_MSG_NOT_SYSTEM_APP = "Permission verification failed. "
95     "A non-system application calls a system API.";
96 constexpr const char* WM_ERROR_CODE_MSG_INVALID_PARAM = "Parameter error. Possible causes: "
97     "1. Mandatory parameters are left unspecified; "
98     "2. Incorrect parameter types; "
99     "3. Parameter verification failed.";
100 constexpr const char* WM_ERROR_CODE_MSG_DEVICE_NOT_SUPPORT = "Capability not supported. "
101     "Failed to call the API due to limited device capabilities.";
102 constexpr const char* WM_ERROR_CODE_MSG_REPEAT_OPERATION = "Repeated operation. Possible causes: "
103     "1. The window is already;"
104     "2. The window is alerady in this state.";
105 constexpr const char* WM_ERROR_CODE_MSG_STATE_ABNORMALLY = "This window state is abnormal. Possible causes: "
106     "The window is not created or destroyed.";
107 constexpr const char* WM_ERROR_CODE_MSG_SYSTEM_ABNORMALLY = "This window manager service works abnormally.";
108 constexpr const char* WM_ERROR_CODE_MSG_INVALID_CALLING = "Unauthorized operation. Possible causes: "
109     "Incorrect window type;";
110 constexpr const char* WM_ERROR_CODE_MSG_STAGE_ABNORMALLY = "This window stage is abnormal. Possible causes: "
111     "The window stage is not created or destroyed;";
112 constexpr const char* WM_ERROR_CODE_MSG_CONTEXT_ABNORMALLY = "This window context is abnormal. Possible causes: "
113     "The context is null.";
114 constexpr const char* WM_ERROR_CODE_MSG_START_ABILITY_FAILED = "Failed to start the ability.";
115 constexpr const char* WM_ERROR_CODE_MSG_INVALID_DISPLAY = "The display device is abnormal. Possible causes: "
116     "The window container could not be found.";
117 constexpr const char* WM_ERROR_CODE_MSG_INVALID_PARENT = "The parent window is invalid.";
118 constexpr const char* WM_ERROR_CODE_MSG_INVALID_OP_IN_CUR_STATUS =
119     "The operation in the current window status is invalid.";
120 constexpr const char* WM_ERROR_CODE_MSG_PIP_DESTROY_FAILED = "Failed to destroy the PiP window.";
121 constexpr const char* WM_ERROR_CODE_MSG_PIP_STATE_ABNORMALLY = "The PiP window state is abnormal.";
122 constexpr const char* WM_ERROR_CODE_MSG_PIP_CREATE_FAILED = "Failed to create the PiP window.";
123 constexpr const char* WM_ERROR_CODE_MSG_PIP_INTERNAL_ERROR = "PiP internal error. Possible causes: "
124     "1.Abnormality in the window relied on by pip, possibly an empty window;"
125     "2.Abnormality in the pip controller.";
126 constexpr const char* WM_ERROR_CODE_MSG_PIP_REPEAT_OPERATION = "Repeated PiP operation. Possible causes: "
127     "This pip has either been pulled up or has already been closed.;";
128 constexpr const char* WM_ERROR_CODE_MSG_ILLEGAL_PARAM = "Parameter validation error. Possible causes: "
129     "1.The value of the parameter is out of the allowed range;"
130     "2.The length of the parameter exceeds the allowed length;"
131     "3.The parameter format is incorrect.";
132 constexpr const char* WM_ERROR_CODE_MSG_UI_EFFECT_ERROR = "Incorrect ui effect calling. Possible causes: "
133     "Must use setBackgroundFilter before animateToBackgroundFilter.";
134 constexpr const char* WM_ERROR_CODE_MSG_TIMEOUT = "API call timed out. Possible causes: "
135     "The waiting time for the synchronous interface call exceeded the limit range.";
136 
137 static std::map<WmErrorCode, const char*> WM_ERROR_CODE_TO_ERROR_MSG_MAP {
138     {WmErrorCode::WM_OK,                              WM_ERROR_CODE_MSG_OK                       },
139     {WmErrorCode::WM_ERROR_NO_PERMISSION,             WM_ERROR_CODE_MSG_NO_PERMISSION            },
140     {WmErrorCode::WM_ERROR_NOT_SYSTEM_APP,            WM_ERROR_CODE_MSG_NOT_SYSTEM_APP           },
141     {WmErrorCode::WM_ERROR_INVALID_PARAM,             WM_ERROR_CODE_MSG_INVALID_PARAM            },
142     {WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT,        WM_ERROR_CODE_MSG_DEVICE_NOT_SUPPORT       },
143     {WmErrorCode::WM_ERROR_REPEAT_OPERATION,          WM_ERROR_CODE_MSG_REPEAT_OPERATION         },
144     {WmErrorCode::WM_ERROR_STATE_ABNORMALLY,          WM_ERROR_CODE_MSG_STATE_ABNORMALLY         },
145     {WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY,         WM_ERROR_CODE_MSG_SYSTEM_ABNORMALLY        },
146     {WmErrorCode::WM_ERROR_INVALID_CALLING,           WM_ERROR_CODE_MSG_INVALID_CALLING          },
147     {WmErrorCode::WM_ERROR_STAGE_ABNORMALLY,          WM_ERROR_CODE_MSG_STAGE_ABNORMALLY         },
148     {WmErrorCode::WM_ERROR_CONTEXT_ABNORMALLY,        WM_ERROR_CODE_MSG_CONTEXT_ABNORMALLY       },
149     {WmErrorCode::WM_ERROR_START_ABILITY_FAILED,      WM_ERROR_CODE_MSG_START_ABILITY_FAILED     },
150     {WmErrorCode::WM_ERROR_INVALID_DISPLAY,           WM_ERROR_CODE_MSG_INVALID_DISPLAY          },
151     {WmErrorCode::WM_ERROR_INVALID_PARENT,            WM_ERROR_CODE_MSG_INVALID_PARENT           },
152     {WmErrorCode::WM_ERROR_INVALID_OP_IN_CUR_STATUS,  WM_ERROR_CODE_MSG_INVALID_OP_IN_CUR_STATUS },
153     {WmErrorCode::WM_ERROR_PIP_DESTROY_FAILED,        WM_ERROR_CODE_MSG_PIP_DESTROY_FAILED       },
154     {WmErrorCode::WM_ERROR_PIP_STATE_ABNORMALLY,      WM_ERROR_CODE_MSG_PIP_STATE_ABNORMALLY     },
155     {WmErrorCode::WM_ERROR_PIP_CREATE_FAILED,         WM_ERROR_CODE_MSG_PIP_CREATE_FAILED        },
156     {WmErrorCode::WM_ERROR_PIP_INTERNAL_ERROR,        WM_ERROR_CODE_MSG_PIP_INTERNAL_ERROR       },
157     {WmErrorCode::WM_ERROR_PIP_REPEAT_OPERATION,      WM_ERROR_CODE_MSG_PIP_REPEAT_OPERATION     },
158     {WmErrorCode::WM_ERROR_ILLEGAL_PARAM,             WM_ERROR_CODE_MSG_ILLEGAL_PARAM            },
159     {WmErrorCode::WM_ERROR_UI_EFFECT_ERROR,           WM_ERROR_CODE_MSG_UI_EFFECT_ERROR          },
160     {WmErrorCode::WM_ERROR_TIMEOUT,                   WM_ERROR_CODE_MSG_TIMEOUT                  },
161 };
162 
163 constexpr const char* DM_ERROR_MSG_OK = "ok";
164 constexpr const char* DM_ERROR_MSG_INIT_DMS_PROXY_LOCKED = "init dms proxy locked";
165 constexpr const char* DM_ERROR_MSG_IPC_FAILED = "ipc failed";
166 constexpr const char* DM_ERROR_MSG_REMOTE_CREATE_FAILED = "remote create failed";
167 constexpr const char* DM_ERROR_MSG_NULLPTR = "nullptr";
168 constexpr const char* DM_ERROR_MSG_INVALID_PARAM = "invalid param";
169 constexpr const char* DM_ERROR_MSG_WRITE_INTERFACE_TOKEN_FAILED = "write interface token failed";
170 constexpr const char* DM_ERROR_MSG_DEATH_RECIPIENT = "death recipient";
171 constexpr const char* DM_ERROR_MSG_INVALID_MODE_ID = "invalid mode id";
172 constexpr const char* DM_ERROR_MSG_WRITE_DATA_FAILED = "write data failed";
173 constexpr const char* DM_ERROR_MSG_RENDER_SERVICE_FAILED = "render service failed";
174 constexpr const char* DM_ERROR_MSG_UNREGISTER_AGENT_FAILED = "unregister agent failed";
175 constexpr const char* DM_ERROR_MSG_INVALID_CALLING = "invalid calling";
176 constexpr const char* DM_ERROR_MSG_INVALID_PERMISSION = "invalid permission";
177 constexpr const char* DM_ERROR_MSG_NOT_SYSTEM_APP = "not system app";
178 constexpr const char* DM_ERROR_MSG_DEVICE_NOT_SUPPORT = "device not support";
179 constexpr const char* DM_ERROR_MSG_UNKNOWN = "unknown";
180 
181 static std::map<DMError, const char*> DM_ERROR_TO_ERROR_MSG_MAP {
182     {DMError::DM_OK,                                    DM_ERROR_MSG_OK                           },
183     {DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED,           DM_ERROR_MSG_INIT_DMS_PROXY_LOCKED        },
184     {DMError::DM_ERROR_IPC_FAILED,                      DM_ERROR_MSG_IPC_FAILED                   },
185     {DMError::DM_ERROR_REMOTE_CREATE_FAILED,            DM_ERROR_MSG_REMOTE_CREATE_FAILED         },
186     {DMError::DM_ERROR_NULLPTR,                         DM_ERROR_MSG_NULLPTR                      },
187     {DMError::DM_ERROR_INVALID_PARAM,                   DM_ERROR_MSG_INVALID_PARAM                },
188     {DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED,    DM_ERROR_MSG_WRITE_INTERFACE_TOKEN_FAILED },
189     {DMError::DM_ERROR_DEATH_RECIPIENT,                 DM_ERROR_MSG_DEATH_RECIPIENT              },
190     {DMError::DM_ERROR_INVALID_MODE_ID,                 DM_ERROR_MSG_INVALID_MODE_ID              },
191     {DMError::DM_ERROR_WRITE_DATA_FAILED,               DM_ERROR_MSG_WRITE_DATA_FAILED            },
192     {DMError::DM_ERROR_RENDER_SERVICE_FAILED,           DM_ERROR_MSG_RENDER_SERVICE_FAILED        },
193     {DMError::DM_ERROR_UNREGISTER_AGENT_FAILED,         DM_ERROR_MSG_UNREGISTER_AGENT_FAILED      },
194     {DMError::DM_ERROR_INVALID_CALLING,                 DM_ERROR_MSG_INVALID_CALLING              },
195     {DMError::DM_ERROR_INVALID_PERMISSION,              DM_ERROR_MSG_INVALID_PERMISSION           },
196     {DMError::DM_ERROR_NOT_SYSTEM_APP,                  DM_ERROR_MSG_NOT_SYSTEM_APP               },
197     {DMError::DM_ERROR_DEVICE_NOT_SUPPORT,              DM_ERROR_MSG_DEVICE_NOT_SUPPORT           },
198     {DMError::DM_ERROR_UNKNOWN,                         DM_ERROR_MSG_UNKNOWN                      },
199 };
200 
201 constexpr const char* DM_ERROR_CODE_MSG_OK = "ok";
202 constexpr const char* DM_ERROR_CODE_MSG_NO_PERMISSION = "no permission";
203 constexpr const char* DM_ERROR_CODE_MSG_NOT_SYSTEM_APP = "not system app";
204 constexpr const char* DM_ERROR_CODE_MSG_INVALID_PARAM = "invalid param";
205 constexpr const char* DM_ERROR_CODE_MSG_DEVICE_NOT_SUPPORT = "device not support";
206 constexpr const char* DM_ERROR_CODE_MSG_INVALID_SCREEN = "invalid screen";
207 constexpr const char* DM_ERROR_CODE_MSG_INVALID_CALLING = "Unauthorized operation. Possible cause: "
208     "The creator and destroyer of the virtual screen are inconsistent.";
209 constexpr const char* DM_ERROR_CODE_MSG_SYSTEM_INNORMAL = "system innormal";
210 
211 static std::map<DmErrorCode, const char*> DM_ERROR_CODE_TO_ERROR_MSG_MAP {
212     {DmErrorCode::DM_OK,                              DM_ERROR_CODE_MSG_OK                 },
213     {DmErrorCode::DM_ERROR_NO_PERMISSION,             DM_ERROR_CODE_MSG_NO_PERMISSION      },
214     {DmErrorCode::DM_ERROR_NOT_SYSTEM_APP,            DM_ERROR_CODE_MSG_NOT_SYSTEM_APP     },
215     {DmErrorCode::DM_ERROR_INVALID_PARAM,             DM_ERROR_CODE_MSG_INVALID_PARAM      },
216     {DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT,        DM_ERROR_CODE_MSG_DEVICE_NOT_SUPPORT },
217     {DmErrorCode::DM_ERROR_INVALID_SCREEN,            DM_ERROR_CODE_MSG_INVALID_SCREEN     },
218     {DmErrorCode::DM_ERROR_INVALID_CALLING,           DM_ERROR_CODE_MSG_INVALID_CALLING    },
219     {DmErrorCode::DM_ERROR_SYSTEM_INNORMAL,           DM_ERROR_CODE_MSG_SYSTEM_INNORMAL    },
220 };
221 
222 template<class T>
CreateJsValue(napi_env env,const T & value)223 napi_value JsErrUtils::CreateJsValue(napi_env env, const T& value)
224 {
225     using ValueType = std::remove_cv_t<std::remove_reference_t<T>>;
226     napi_value result = nullptr;
227     if constexpr (std::is_same_v<ValueType, bool>) {
228         napi_get_boolean(env, value, &result);
229         return result;
230     } else if constexpr (std::is_arithmetic_v<ValueType>) {
231         return CreateJsNumber(env, value);
232     } else if constexpr (std::is_same_v<ValueType, std::string>) {
233         napi_create_string_utf8(env, value.c_str(), value.length(), &result);
234         return result;
235     } else if constexpr (std::is_enum_v<ValueType>) {
236         return CreateJsNumber(env, static_cast<std::make_signed_t<ValueType>>(value));
237     } else if constexpr (std::is_same_v<ValueType, const char*>) {
238         (value != nullptr) ? napi_create_string_utf8(env, value, strlen(value), &result) :
239             napi_get_undefined(env, &result);
240         return result;
241     }
242 }
243 
GetErrorMsg(const WMError & errorCode)244 std::string JsErrUtils::GetErrorMsg(const WMError& errorCode)
245 {
246     return WM_ERROR_TO_ERROR_MSG_MAP.find(errorCode) != WM_ERROR_TO_ERROR_MSG_MAP.end() ?
247         WM_ERROR_TO_ERROR_MSG_MAP.at(errorCode) : "";
248 }
249 
GetErrorMsg(const WmErrorCode & errorCode)250 std::string JsErrUtils::GetErrorMsg(const WmErrorCode& errorCode)
251 {
252     return WM_ERROR_CODE_TO_ERROR_MSG_MAP.find(errorCode) != WM_ERROR_CODE_TO_ERROR_MSG_MAP.end() ?
253         WM_ERROR_CODE_TO_ERROR_MSG_MAP.at(errorCode) : "";
254 }
255 
GetErrorMsg(const DMError & errorCode)256 std::string JsErrUtils::GetErrorMsg(const DMError& errorCode)
257 {
258     return DM_ERROR_TO_ERROR_MSG_MAP.find(errorCode) != DM_ERROR_TO_ERROR_MSG_MAP.end() ?
259         DM_ERROR_TO_ERROR_MSG_MAP.at(errorCode) : "";
260 }
261 
GetErrorMsg(const DmErrorCode & errorCode)262 std::string JsErrUtils::GetErrorMsg(const DmErrorCode& errorCode)
263 {
264     return DM_ERROR_CODE_TO_ERROR_MSG_MAP.find(errorCode) != DM_ERROR_CODE_TO_ERROR_MSG_MAP.end() ?
265         DM_ERROR_CODE_TO_ERROR_MSG_MAP.at(errorCode) : "";
266 }
267 
CreateJsError(napi_env env,const WMError & errorCode,std::string msg)268 napi_value JsErrUtils::CreateJsError(napi_env env, const WMError& errorCode, std::string msg)
269 {
270     napi_value result = nullptr;
271     napi_create_error(env, CreateJsValue(env, static_cast<int32_t>(errorCode)),
272         CreateJsValue(env, msg == "" ? GetErrorMsg(errorCode) : msg), &result);
273     return result;
274 }
275 
CreateJsError(napi_env env,const WmErrorCode & errorCode,std::string msg)276 napi_value JsErrUtils::CreateJsError(napi_env env, const WmErrorCode& errorCode, std::string msg)
277 {
278     napi_value result = nullptr;
279     napi_create_error(env, CreateJsValue(env, static_cast<int32_t>(errorCode)),
280         CreateJsValue(env, msg == "" ? GetErrorMsg(errorCode) : msg), &result);
281     return result;
282 }
283 
CreateJsError(napi_env env,const DMError & errorCode,std::string msg)284 napi_value JsErrUtils::CreateJsError(napi_env env, const DMError& errorCode, std::string msg)
285 {
286     napi_value result = nullptr;
287     napi_create_error(env, CreateJsValue(env, static_cast<int32_t>(errorCode)),
288         CreateJsValue(env, msg == "" ? GetErrorMsg(errorCode) : msg), &result);
289     return result;
290 }
291 
CreateJsError(napi_env env,const DmErrorCode & errorCode,std::string msg)292 napi_value JsErrUtils::CreateJsError(napi_env env, const DmErrorCode& errorCode, std::string msg)
293 {
294     napi_value result = nullptr;
295     napi_create_error(env, CreateJsValue(env, static_cast<int32_t>(errorCode)),
296         CreateJsValue(env, msg == "" ? GetErrorMsg(errorCode) : msg), &result);
297     return result;
298 }
299 } // namespace OHOS::Rosen
300