1 // Copyright 2021 Google LLC
2 //
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 // https://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 #include "curl_util.h" // NOLINT(build/include)
16
17 #include "absl/status/statusor.h"
18 #include "absl/strings/str_cat.h"
19
20 namespace curl {
21
StrError(curl::CurlApi * api,int curl_error)22 std::string StrError(curl::CurlApi* api, int curl_error) {
23 absl::StatusOr<void*> remote_error_message =
24 api->curl_easy_strerror(static_cast<CURLcode>(curl_error));
25 if (!remote_error_message.ok()) {
26 return absl::StrCat("Code ", curl_error, " (curl_easy_strerror failed)");
27 }
28
29 absl::StatusOr<std::string> error_message =
30 api->sandbox()->GetCString(sapi::v::RemotePtr(*remote_error_message));
31 if (!error_message.ok()) {
32 return absl::StrCat("Code ", curl_error, " (error getting error message)");
33 }
34 return *error_message;
35 }
36
37 } // namespace curl
38