Skip to content

Commit

Permalink
feat: add error handling for display module loading
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Oct 31, 2024
1 parent 9b50a31 commit de1d1e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lua/hurl/history.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ function M.show_last_response()
end

local last_response = response_history[1]
local display = require('hurl.' .. _HURL_GLOBAL_CONFIG.mode)
local ok, display = pcall(require, 'hurl.' .. (_HURL_GLOBAL_CONFIG.mode or 'split'))
if not ok then
utils.notify('Failed to load display module: ' .. display, vim.log.levels.ERROR)
return
end

display.show(last_response, last_response.display_type or 'text')
end
Expand Down
6 changes: 5 additions & 1 deletion lua/hurl/lib/hurl_runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ function M.execute_hurl_cmd(opts, callback)
save_last_hurl_command(cmd)

-- Clear the display and show processing message with Hurl command
local display = require('hurl.' .. _HURL_GLOBAL_CONFIG.mode)
local ok, display = pcall(require, 'hurl.' .. (_HURL_GLOBAL_CONFIG.mode or 'split'))
if not ok then
utils.notify('Failed to load display module: ' .. display, vim.log.levels.ERROR)
return
end
display.clear()

local stdout_data = ''
Expand Down
6 changes: 5 additions & 1 deletion lua/hurl/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ function M.setup()
if last_response then
-- Ensure response_time is a number
last_response.response_time = tonumber(last_response.response_time) or '-'
local display = require('hurl.' .. _HURL_GLOBAL_CONFIG.mode)
local ok, display = pcall(require, 'hurl.' .. (_HURL_GLOBAL_CONFIG.mode or 'split'))
if not ok then
utils.notify('Failed to load display module: ' .. display, vim.log.levels.ERROR)
return
end
display.show(last_response, 'json')
else
utils.notify('No response history available', vim.log.levels.INFO)
Expand Down

0 comments on commit de1d1e8

Please sign in to comment.