137a09cd7Sopenharmony_ci/*
237a09cd7Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
337a09cd7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
437a09cd7Sopenharmony_ci * you may not use this file except in compliance with the License.
537a09cd7Sopenharmony_ci * You may obtain a copy of the License at
637a09cd7Sopenharmony_ci *
737a09cd7Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
837a09cd7Sopenharmony_ci *
937a09cd7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1037a09cd7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1137a09cd7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1237a09cd7Sopenharmony_ci * See the License for the specific language governing permissions and
1337a09cd7Sopenharmony_ci * limitations under the License.
1437a09cd7Sopenharmony_ci */
1537a09cd7Sopenharmony_ci
1637a09cd7Sopenharmony_ci#ifndef POWER_NAPI_ERRORS_H
1737a09cd7Sopenharmony_ci#define POWER_NAPI_ERRORS_H
1837a09cd7Sopenharmony_ci
1937a09cd7Sopenharmony_ci#include <map>
2037a09cd7Sopenharmony_ci#include <string>
2137a09cd7Sopenharmony_ci
2237a09cd7Sopenharmony_ci#include "napi/native_node_api.h"
2337a09cd7Sopenharmony_ci#include "thermal_mgr_errors.h"
2437a09cd7Sopenharmony_ci
2537a09cd7Sopenharmony_cinamespace OHOS {
2637a09cd7Sopenharmony_cinamespace PowerMgr {
2737a09cd7Sopenharmony_ciclass NapiErrors {
2837a09cd7Sopenharmony_cipublic:
2937a09cd7Sopenharmony_ci    NapiErrors() {}
3037a09cd7Sopenharmony_ci    NapiErrors(ThermalErrors code) : code_(code) {}
3137a09cd7Sopenharmony_ci    napi_value GetNapiError(napi_env& env) const;
3237a09cd7Sopenharmony_ci    napi_value ThrowError(napi_env& env, ThermalErrors code = ThermalErrors::ERR_OK);
3337a09cd7Sopenharmony_ci    inline void Error(ThermalErrors code)
3437a09cd7Sopenharmony_ci    {
3537a09cd7Sopenharmony_ci        code_ = (code != ThermalErrors::ERR_OK) ? code : code_;
3637a09cd7Sopenharmony_ci    }
3737a09cd7Sopenharmony_ci    inline bool IsError() const
3837a09cd7Sopenharmony_ci    {
3937a09cd7Sopenharmony_ci        return code_ != ThermalErrors::ERR_OK;
4037a09cd7Sopenharmony_ci    }
4137a09cd7Sopenharmony_ci
4237a09cd7Sopenharmony_ciprivate:
4337a09cd7Sopenharmony_ci    ThermalErrors code_ {ThermalErrors::ERR_OK};
4437a09cd7Sopenharmony_ci    static std::map<ThermalErrors, std::string> errorTable_;
4537a09cd7Sopenharmony_ci};
4637a09cd7Sopenharmony_ci} // namespace PowerMgr
4737a09cd7Sopenharmony_ci} // namespace OHOS
4837a09cd7Sopenharmony_ci
4937a09cd7Sopenharmony_ci#endif // POWER_NAPI_ERRORS_H
50