diff --git a/packages/client/src/api/api.js b/packages/client/src/api/api.js index b4a137f85d..4062bd3b73 100644 --- a/packages/client/src/api/api.js +++ b/packages/client/src/api/api.js @@ -35,7 +35,8 @@ export const API = createAPIClient({ // We could also log these to sentry. // Or we could check error.status and redirect to login on a 403 etc. onError: error => { - const { status, method, url, message, handled } = error || {} + const { status, method, url, message, handled, suppressErrors } = + error || {} const ignoreErrorUrls = [ "bbtel", "/api/global/self", @@ -49,7 +50,7 @@ export const API = createAPIClient({ } // Notify all errors - if (message) { + if (message && !suppressErrors) { // Don't notify if the URL contains the word analytics as it may be // blocked by browser extensions let ignore = false diff --git a/packages/frontend-core/src/api/index.js b/packages/frontend-core/src/api/index.js index 739e0fe711..05abded61c 100644 --- a/packages/frontend-core/src/api/index.js +++ b/packages/frontend-core/src/api/index.js @@ -75,7 +75,11 @@ export const createAPIClient = config => { let cache = {} // Generates an error object from an API response - const makeErrorFromResponse = async (response, method) => { + const makeErrorFromResponse = async ( + response, + method, + suppressErrors = false + ) => { // Try to read a message from the error let message = response.statusText let json = null @@ -96,6 +100,7 @@ export const createAPIClient = config => { url: response.url, method, handled: true, + suppressErrors, } } @@ -119,6 +124,7 @@ export const createAPIClient = config => { json = true, external = false, parseResponse, + suppressErrors = false, }) => { // Ensure we don't do JSON processing if sending a GET request json = json && method !== "GET" @@ -174,7 +180,7 @@ export const createAPIClient = config => { } } else { delete cache[url] - throw await makeErrorFromResponse(response, method) + throw await makeErrorFromResponse(response, method, suppressErrors) } } diff --git a/packages/frontend-core/src/api/rows.js b/packages/frontend-core/src/api/rows.js index 41ba505d81..8e8570ea2a 100644 --- a/packages/frontend-core/src/api/rows.js +++ b/packages/frontend-core/src/api/rows.js @@ -16,14 +16,16 @@ export const buildRowEndpoints = API => ({ /** * Creates or updates a row in a table. * @param row the row to save + * @param suppressErrors whether or not to suppress error notifications */ - saveRow: async row => { + saveRow: async (row, suppressErrors = false) => { if (!row?.tableId) { return } return await API.post({ url: `/api/${row.tableId}/rows`, body: row, + suppressErrors, }) }, diff --git a/packages/frontend-core/src/components/grid/stores/rows.js b/packages/frontend-core/src/components/grid/stores/rows.js index 9e12e16eb1..d7e623692e 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.js +++ b/packages/frontend-core/src/components/grid/stores/rows.js @@ -4,6 +4,8 @@ import { notifications } from "@budibase/bbui" import { NewRowID, RowPageSize } from "../lib/constants" import { tick } from "svelte" +const SuppressErrors = true + export const createStores = () => { const rows = writable([]) const table = writable(null) @@ -209,7 +211,10 @@ export const deriveStores = context => { const addRow = async (row, idx, bubble = false) => { try { // Create row - const newRow = await API.saveRow({ ...row, tableId: get(tableId) }) + const newRow = await API.saveRow( + { ...row, tableId: get(tableId) }, + SuppressErrors + ) // Update state if (idx != null) { @@ -336,7 +341,10 @@ export const deriveStores = context => { ...state, [rowId]: true, })) - const saved = await API.saveRow({ ...row, ...get(rowChangeCache)[rowId] }) + const saved = await API.saveRow( + { ...row, ...get(rowChangeCache)[rowId] }, + SuppressErrors + ) // Update state after a successful change if (saved?._id) {