Kong/insomnia · error · Error
dataURI(): response body is not defined
Error message
dataURI(): response body is not defined
What it means
Guard in Response.dataURI: neither the response stream nor the body contains data, so there is nothing to encode into a data: URI. Fires when a script calls response.dataURI() on a response whose body was never populated.
Solutions
- Check the response has a body before calling dataURI()
- Handle empty-body responses (204, empty 200) separately in the script
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at packages/insomnia-scripting-environment/src/objects/response.ts:153 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Kong/insomnia@d9bb2b0142 (2026-08-26).
Data as JSON: /api/errors/1ea69a2e3fc393c9.
Report an issue: GitHub.
Appendix: source
Thrown at packages/insomnia-scripting-environment/src/objects/response.ts:153
}
});
}
return {
mimeType: mimeInfo.mimeType,
mimeFormat: mimeInfo.mimeFormat,
charset: mimeInfo.charset,
fileExtension: fileInfo.extension,
fileName: fileInfo.name,
contentType: contentType?.valueOf() || 'application/octet-stream',
};
}
dataURI() {
const contentInfo = this.contentInfo();
const bodyInBase64 = this.stream || this.body;
if (!bodyInBase64) {
throw new Error('dataURI(): response body is not defined');
}
return `data:${contentInfo.contentType};baseg4, ${bodyInBase64}`;
}
json(reviver?: (key: string, value: any) => any, _strict?: boolean) {
// TODO: enable strict after common module is introduced
try {
return JSON.parse(this.body.toString(), reviver);
} catch (e) {
throw new Error(`json: failed to parse: ${e}`);
}
}
jsonp(_reviver?: (key: string, value: any) => any, _strict?: boolean) {
throw unsupportedError('jsonp()');
}
View on GitHub (pinned to d9bb2b0142)