Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(feedbacks): different function creators for errors & success #134

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions composables/api_fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ export function api_fetch(
const { valid, error } = validate_schema(schema, body)

if (!valid) {
feedback_store.add_feedback({
type: "error",
code: 400,
route: schema.$id,
name: "Bad request",
description: error,
})
feedback_store.add_error(400, schema.$id, "Bad request", error)
throw new Error(schema.$id.concat(": ", error))
}

Expand All @@ -40,13 +34,12 @@ export function api_fetch(
...request_options,
onRequestError({ error }) {
geode_store.stop_request()
feedback_store.add_feedback({
type: "error",
code: error.code,
route: schema.$id,
name: error.message,
description: error.stack,
})
feedback_store.add_error(
error.code,
schema.$id,
error.message,
error.stack,
)
if (request_error_function) {
request_error_function(error)
}
Expand All @@ -61,13 +54,12 @@ export function api_fetch(
},
onResponseError({ response }) {
geode_store.stop_request()
feedback_store.add_feedback({
type: "error",
code: response.status,
route: schema.$id,
name: response._data.name,
description: response._data.description,
})
feedback_store.add_error(
response.status,
schema.$id,
response._data.name,
response._data.description,
)
if (response_error_function) {
response_error_function(response)
}
Expand Down
21 changes: 7 additions & 14 deletions composables/upload_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ export async function upload_file(
...request_options,
onRequestError({ error }) {
geode_store.stop_request()
feedback_store.add_feedback({
type: "error",
code: error.code,
route: route,
name: error.message,
description: error.stack,
})
feedback_store.add_error(error.code, route, error.message, error.stack)
if (request_error_function) {
request_error_function(error)
}
Expand All @@ -43,13 +37,12 @@ export async function upload_file(
},
onResponseError({ response }) {
geode_store.stop_request()
feedback_store.add_feedback({
type: "error",
code: response.status,
route: route,
name: response._data.name,
description: response._data.description,
})
feedback_store.add_error(
response.status,
route,
response._data.name,
response._data.description,
)
if (response_error_function) {
response_error_function(response)
}
Expand Down
21 changes: 7 additions & 14 deletions composables/viewer_call.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ export function viewer_call(
const { valid, error } = validate_schema(schema, params)

if (!valid) {
feedback_store.add_feedback({
type: "error",
code: 400,
route: schema.route,
name: "Bad request",
description: error,
})
feedback_store.add_error(400, schema.route, "Bad request", error)
throw new Error(schema.route.concat(": ", error))
}

Expand Down Expand Up @@ -42,13 +36,12 @@ export function viewer_call(
},
)
.catch((error) => {
feedback_store.add_feedback({
type: "error",
code: error.code,
route: schema.route,
name: error.message,
description: error.message,
})
feedback_store.add_error(
error.code,
schema.route,
error.message,
error.message,
)
if (response_error_function) {
response_error_function(error)
}
Expand Down
16 changes: 14 additions & 2 deletions stores/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@ export const use_feedback_store = defineStore("feedback", {
server_error: false,
}),
actions: {
add_feedback(feedback) {
this.feedbacks.push(feedback)
add_error(code, route, name, description) {
this.feedbacks.push({
type: "error",
code,
route,
name,
description,
})
},
add_success(description) {
this.feedbacks.push({
type: "success",
description,
})
},
delete_feedback(feedback_index) {
this.feedbacks.splice(feedback_index, 1)
Expand Down
14 changes: 6 additions & 8 deletions test/components/FeedBack/Snackers.nuxt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ describe("FeedBackSnackers.vue", async () => {
console.log("wrapper", wrapper)

const feedback_store = use_feedback_store()
const error = {
type: "error",
code: 404,
route: "/test",
name: "Test message",
description: "Test desription",
}
await feedback_store.add_feedback(error)
await feedback_store.add_error(
404,
"/test",
"Test message",
"Test desription",
)
expect(feedback_store.feedbacks.length).toBe(1)
const v_btn = await wrapper.findComponent(components.VBtn)
console.log("v_btn", v_btn)
Expand Down
17 changes: 9 additions & 8 deletions test/stores/Feedback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ describe("Feedback store", () => {
setActivePinia(createPinia())
})

it("add_feedback", () => {
it("add_error", () => {
const feedback_store = use_feedback_store()
expect(feedback_store.feedbacks.length).toBe(0)
feedback_store.add_feedback({
type: "error",
code: 500,
route: "/test",
name: "test message",
description: "test description",
})
feedback_store.add_error(500, "/test", "test message", "test description")
expect(feedback_store.feedbacks.length).toBe(1)
})

it("add_success", () => {
const feedback_store = use_feedback_store()
expect(feedback_store.feedbacks.length).toBe(0)
feedback_store.add_success(500, "/test", "test message", "test description")
expect(feedback_store.feedbacks.length).toBe(1)
})

Expand Down