Frappe.local.response.type == "pdf" results in error: Cannot read properties of undefined (reading 'responseText')


I’m trying to create a PDF from custom HTML. I followed this example (Utility Functions) but when I call this function with from Javascript, I get this error:

Unable to handle failed response
request.js:327 TypeError: Cannot read properties of undefined (reading 'responseText')
    at 200 (request.js:127:61)
    at Object.<anonymous> (request.js:320:6)
    at i (jquery.min.js:2:27151)
    at Object.fireWith [as rejectWith] (jquery.min.js:2:27914)
    at z (jquery.min.js:4:12084)
    at XMLHttpRequest.<anonymous> (jquery.min.js:4:15619)
(anonym)	@	request.js:327
i	@	jquery.min.js:2
fireWith	@	jquery.min.js:2
z	@	jquery.min.js:4
(anonym)	@	jquery.min.js:4
load (async)		
send	@	jquery.min.js:4
ajax	@	jquery.min.js:4	@	request.js:253	@	request.js:103
user_info	@	cdsc_student__list_js:23
dispatch	@	jquery.min.js:3
r.handle	@	jquery.min.js:3

What do I miss?