fix: catch an edge case while saving request

This commit is contained in:
liyasthomas
2021-12-05 18:21:41 +05:30
parent fb6015ce26
commit e7535d505e
3 changed files with 23 additions and 5 deletions

View File

@@ -198,6 +198,7 @@ import {
getRESTSaveContext,
getRESTRequest,
restRequest$,
setRESTSaveContext,
} from "~/newstore/RESTSession"
import { editRESTRequest } from "~/newstore/collections"
import { runRESTRequest$ } from "~/helpers/RequestRunner"
@@ -418,8 +419,17 @@ const saveRequest = () => {
}
if (saveCtx.originLocation === "user-collection") {
editRESTRequest(saveCtx.folderPath, saveCtx.requestIndex, getRESTRequest())
toast.success(`${t("request.saved")}`)
try {
editRESTRequest(
saveCtx.folderPath,
saveCtx.requestIndex,
getRESTRequest()
)
toast.success(`${t("request.saved")}`)
} catch (e) {
setRESTSaveContext(null)
saveRequest()
}
} else if (saveCtx.originLocation === "team-collection") {
const req = getRESTRequest()

View File

@@ -73,7 +73,7 @@
</template>
<script lang="ts">
import { defineComponent } from "@nuxtjs/composition-api"
import { defineComponent, onBeforeUnmount } from "@nuxtjs/composition-api"
import { useKeybindingDisabler } from "~/helpers/keybindings"
const PORTAL_DOM_ID = "hoppscotch-modal-portal"
@@ -118,9 +118,12 @@ export default defineComponent({
setup() {
const { disableKeybindings, enableKeybindings } = useKeybindingDisabler()
onBeforeUnmount(() => {
enableKeybindings()
})
return {
disableKeybindings,
enableKeybindings,
}
},
data() {
@@ -154,7 +157,6 @@ export default defineComponent({
methods: {
close() {
this.$emit("close")
this.enableKeybindings()
},
onKeyDown(e: KeyboardEvent) {
if (e.key === "Escape" && this.stackId === stack.peek()) {

View File

@@ -744,6 +744,12 @@ export function editRESTRequest(
requestIndex: number,
requestNew: HoppRESTRequest
) {
const indexPaths = path.split("/").map((x) => parseInt(x))
if (
!navigateToFolderWithIndexPath(restCollectionStore.value.state, indexPaths)
)
throw new Error("Path not found")
restCollectionStore.dispatch({
dispatcher: "editRequest",
payload: {