|
232 | 232 | -- @param opts curl arguments |
233 | 233 | local function curl_cmd(opts) |
234 | 234 | local res = curl[opts.method](opts) |
| 235 | + if opts.dry_run then |
| 236 | + print( |
| 237 | + '[rest.nvim] Request preview:\n' |
| 238 | + .. 'curl ' |
| 239 | + .. table.concat(res, ' ') |
| 240 | + ) |
| 241 | + return |
| 242 | + end |
| 243 | + |
235 | 244 | local res_bufnr = get_or_create_buf() |
236 | 245 | local parsed_url = parse_url(fn.getline('.')) |
237 | 246 | local json_body = false |
|
301 | 310 |
|
302 | 311 | -- run will retrieve the required request information from the current buffer |
303 | 312 | -- and then execute curl |
304 | | -local function run() |
| 313 | +local function run(verbose) |
305 | 314 | local bufnr = api.nvim_win_get_buf(0) |
306 | 315 | local parsed_url = parse_url(fn.getline('.')) |
307 | 316 | local last_query_line_number = fn.line('.') |
@@ -331,18 +340,20 @@ local function run() |
331 | 340 | local auth = get_auth(bufnr, last_query_line_number) |
332 | 341 | local accept = get_accept(bufnr, last_query_line_number) |
333 | 342 |
|
334 | | - local success_req = pcall(curl_cmd, { |
| 343 | + local success_req, req_err = pcall(curl_cmd, { |
335 | 344 | method = parsed_url.method:lower(), |
336 | 345 | url = parsed_url.url, |
337 | 346 | headers = headers, |
338 | 347 | accept = accept, |
339 | 348 | body = body, |
340 | 349 | auth = auth, |
| 350 | + dry_run = verbose and verbose or false, |
341 | 351 | }) |
342 | 352 |
|
343 | 353 | if not success_req then |
344 | 354 | error( |
345 | | - '[rest.nvim] Failed to perform the request.\nMake sure that you have entered the proper URL and the server is running.', |
| 355 | + '[rest.nvim] Failed to perform the request.\nMake sure that you have entered the proper URL and the server is running.\n\nTraceback: ' |
| 356 | + .. req_err, |
346 | 357 | 2 |
347 | 358 | ) |
348 | 359 | end |
|
0 commit comments