Skip to content

Repeated pattern in components interacting with models #32

@uier

Description

@uier

每個有做 POST/PUT/DELETE 的元件都會有這段 pattern 出現,可以討論是否適合包成 hook

至少 catch 那邊的邏輯可以抽出來

async function submit() {
isLoading.value = true;
try {
const { annId } = (
await api.Announcement.create({
...newAnnouncement,
courseName: route.params.name as string,
})
).data;
router.push(`/course/${route.params.name}/announcements/${annId}`);
} catch (error) {
if (axios.isAxiosError(error) && error.response?.data?.message) {
errorMsg.value = error.response.data.message;
} else {
errorMsg.value = "Unknown error occurred :(";
}
throw error;
} finally {
isLoading.value = false;
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededquestionFurther information is requested

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions