@@ -229,14 +229,15 @@ local function format_body(bufnr, headers, res)
229229 logger :error (" Error running formatter '" .. fmt .. " ' on response body:\n " .. stdout )
230230 end
231231 end
232- else
232+ elseif res_type ~= nil then
233233 --- @diagnostic disable-next-line need-check-nil
234234 logger :info (
235235 " Could not find a formatter for the body type "
236236 .. res_type
237237 .. " returned in the request, the results will not be formatted"
238238 )
239239 end
240+
240241 body = vim .split (res .body , " \n " )
241242 table.insert (body , 1 , res .method .. " " .. res .url )
242243 table.insert (body , 2 , headers [1 ]) -- HTTP/X and status code + meaning
@@ -249,11 +250,12 @@ local function format_body(bufnr, headers, res)
249250 table.remove (winbar .pane_map [2 ].contents , 1 )
250251
251252 -- add syntax highlights for response
252- vim .api .nvim_buf_call (bufnr , function ()
253- local syntax_file = vim .fn .expand (string.format (" $VIMRUNTIME/syntax/%s.vim" , res_type ))
254- if vim .fn .filereadable (syntax_file ) == 1 then
255- vim .cmd (string.gsub (
256- [[
253+ if res_type ~= nil then
254+ vim .api .nvim_buf_call (bufnr , function ()
255+ local syntax_file = vim .fn .expand (string.format (" $VIMRUNTIME/syntax/%s.vim" , res_type ))
256+ if vim .fn .filereadable (syntax_file ) == 1 then
257+ vim .cmd (string.gsub (
258+ [[
257259 if exists("b:current_syntax")
258260 unlet b:current_syntax
259261 endif
@@ -262,11 +264,12 @@ local function format_body(bufnr, headers, res)
262264
263265 let b:current_syntax = "httpResult"
264266 ]] ,
265- " %%s" ,
266- res_type
267- ))
268- end
269- end )
267+ " %%s" ,
268+ res_type
269+ ))
270+ end
271+ end )
272+ end
270273 end
271274 --- @diagnostic disable-next-line inject-field
272275 winbar .pane_map [1 ].contents = body
0 commit comments