File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ static int w_request(lua_State *L)
9494 auto url = w_checkstring (L, 1 );
9595 HTTPSClient::Request req (url);
9696
97+ std::string errorMessage (" No applicable implementation found" );
9798 bool foundClient = false ;
9899 bool advanced = false ;
99100
@@ -124,10 +125,21 @@ static int w_request(lua_State *L)
124125 for (size_t i = 0 ; clients[i]; ++i)
125126 {
126127 HTTPSClient &client = *clients[i];
128+ HTTPSClient::Reply reply;
129+
127130 if (!client.valid ())
128131 continue ;
129132
130- auto reply = client.request (req);
133+ try
134+ {
135+ reply = client.request (req);
136+ }
137+ catch (const std::exception& e)
138+ {
139+ errorMessage = e.what ();
140+ break ;
141+ }
142+
131143 lua_pushinteger (L, reply.responseCode );
132144 w_pushstring (L, reply.body );
133145
@@ -149,12 +161,10 @@ static int w_request(lua_State *L)
149161 if (!foundClient)
150162 {
151163 lua_pushnil (L);
152- lua_pushstring (L, " No applicable implementation found" );
153- if (advanced)
154- lua_pushnil (L);
164+ lua_pushstring (L, errorMessage.c_str ());
155165 }
156166
157- return advanced ? 3 : 2 ;
167+ return ( advanced && foundClient) ? 3 : 2 ;
158168}
159169
160170extern " C" int DLLEXPORT luaopen_https (lua_State *L)
You can’t perform that action at this time.
0 commit comments