fix: null reference when parsing error responses (fixes #1749)

This commit is contained in:
Andrew Bastin
2021-07-28 00:47:52 -04:00
parent 8bf9a1e821
commit d5cb9f135f
2 changed files with 12 additions and 4 deletions

View File

@@ -10,9 +10,9 @@
<component :is="lens.renderer" :response="response" /> <component :is="lens.renderer" :response="response" />
</SmartTab> </SmartTab>
<SmartTab <SmartTab
v-if="Object.keys(response.headers).length !== 0" v-if="headerLength"
id="headers" id="headers"
:label="`Headers \xA0 • \xA0 ${Object.keys(response.headers).length}`" :label="`Headers \xA0 • \xA0 ${headerLength}`"
> >
<LensesHeadersRenderer :headers="response.headers" /> <LensesHeadersRenderer :headers="response.headers" />
</SmartTab> </SmartTab>
@@ -31,7 +31,14 @@ export default {
response: { type: Object, default: () => {} }, response: { type: Object, default: () => {} },
}, },
computed: { computed: {
headerLength() {
if (!this.response || !this.response.headers) return 0
return Object.keys(this.response.headers).length
},
validLenses() { validLenses() {
if (!this.response) return []
return getSuitableLenses(this.response) return getSuitableLenses(this.response)
}, },
}, },

View File

@@ -1626,10 +1626,11 @@ export default {
// tests // tests
const syntheticResponse = { const syntheticResponse = {
status: this.response.status, status: this.response.status,
body: this.response.body, body: this.response.body || new Uint8Array([]),
headers: this.response.headers, headers: this.response.headers || [],
} }
this.response.body = this.response.body || new Uint8Array([])
// Parse JSON body // Parse JSON body
if ( if (
syntheticResponse.headers["content-type"] && syntheticResponse.headers["content-type"] &&