refactor: add safety coersion for loading rest requests from external source

This commit is contained in:
Andrew Bastin
2022-01-05 16:15:06 +05:30
parent 137d562c86
commit ac979239e8
6 changed files with 73 additions and 23 deletions

View File

@@ -127,7 +127,11 @@ import "splitpanes/dist/splitpanes.css"
import { map } from "rxjs/operators"
import { Subscription } from "rxjs"
import isEqual from "lodash/isEqual"
import { HoppRESTRequest, HoppRESTAuthOAuth2 } from "@hoppscotch/data"
import {
HoppRESTRequest,
HoppRESTAuthOAuth2,
safelyExtractRESTRequest,
} from "@hoppscotch/data"
import { useSetting } from "~/newstore/settings"
import {
restActiveParamsCount$,
@@ -138,6 +142,7 @@ import {
restAuth$,
useTestScript,
usePreRequestScript,
getDefaultRESTRequest,
} from "~/newstore/RESTSession"
import { translateExtURLParams } from "~/helpers/RESTExtURLParams"
import {
@@ -158,7 +163,12 @@ function bindRequestToURLParams() {
// If query params are empty, or contains code or error param (these are from Oauth Redirect)
// We skip URL params parsing
if (Object.keys(query).length === 0 || query.code || query.error) return
setRESTRequest(translateExtURLParams(query))
setRESTRequest(
safelyExtractRESTRequest(
translateExtURLParams(query),
getDefaultRESTRequest()
)
)
})
}
@@ -226,7 +236,9 @@ export default defineComponent({
const confirmSync = ref(false)
const syncRequest = () => {
setRESTRequest(requestForSync.value!)
setRESTRequest(
safelyExtractRESTRequest(requestForSync.value!, getDefaultRESTRequest())
)
}
setupRequestSync(confirmSync, requestForSync)