Add functionality to suppress errors to avoid spam in grids in client apps
This commit is contained in:
parent
9942956a06
commit
757d2d11ef
|
@ -35,7 +35,8 @@ export const API = createAPIClient({
|
||||||
// We could also log these to sentry.
|
// We could also log these to sentry.
|
||||||
// Or we could check error.status and redirect to login on a 403 etc.
|
// Or we could check error.status and redirect to login on a 403 etc.
|
||||||
onError: error => {
|
onError: error => {
|
||||||
const { status, method, url, message, handled } = error || {}
|
const { status, method, url, message, handled, suppressErrors } =
|
||||||
|
error || {}
|
||||||
const ignoreErrorUrls = [
|
const ignoreErrorUrls = [
|
||||||
"bbtel",
|
"bbtel",
|
||||||
"/api/global/self",
|
"/api/global/self",
|
||||||
|
@ -49,7 +50,7 @@ export const API = createAPIClient({
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify all errors
|
// Notify all errors
|
||||||
if (message) {
|
if (message && !suppressErrors) {
|
||||||
// Don't notify if the URL contains the word analytics as it may be
|
// Don't notify if the URL contains the word analytics as it may be
|
||||||
// blocked by browser extensions
|
// blocked by browser extensions
|
||||||
let ignore = false
|
let ignore = false
|
||||||
|
|
|
@ -75,7 +75,11 @@ export const createAPIClient = config => {
|
||||||
let cache = {}
|
let cache = {}
|
||||||
|
|
||||||
// Generates an error object from an API response
|
// 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
|
// Try to read a message from the error
|
||||||
let message = response.statusText
|
let message = response.statusText
|
||||||
let json = null
|
let json = null
|
||||||
|
@ -96,6 +100,7 @@ export const createAPIClient = config => {
|
||||||
url: response.url,
|
url: response.url,
|
||||||
method,
|
method,
|
||||||
handled: true,
|
handled: true,
|
||||||
|
suppressErrors,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +124,7 @@ export const createAPIClient = config => {
|
||||||
json = true,
|
json = true,
|
||||||
external = false,
|
external = false,
|
||||||
parseResponse,
|
parseResponse,
|
||||||
|
suppressErrors = false,
|
||||||
}) => {
|
}) => {
|
||||||
// Ensure we don't do JSON processing if sending a GET request
|
// Ensure we don't do JSON processing if sending a GET request
|
||||||
json = json && method !== "GET"
|
json = json && method !== "GET"
|
||||||
|
@ -174,7 +180,7 @@ export const createAPIClient = config => {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
delete cache[url]
|
delete cache[url]
|
||||||
throw await makeErrorFromResponse(response, method)
|
throw await makeErrorFromResponse(response, method, suppressErrors)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,14 +16,16 @@ export const buildRowEndpoints = API => ({
|
||||||
/**
|
/**
|
||||||
* Creates or updates a row in a table.
|
* Creates or updates a row in a table.
|
||||||
* @param row the row to save
|
* @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) {
|
if (!row?.tableId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return await API.post({
|
return await API.post({
|
||||||
url: `/api/${row.tableId}/rows`,
|
url: `/api/${row.tableId}/rows`,
|
||||||
body: row,
|
body: row,
|
||||||
|
suppressErrors,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ import { notifications } from "@budibase/bbui"
|
||||||
import { NewRowID, RowPageSize } from "../lib/constants"
|
import { NewRowID, RowPageSize } from "../lib/constants"
|
||||||
import { tick } from "svelte"
|
import { tick } from "svelte"
|
||||||
|
|
||||||
|
const SuppressErrors = true
|
||||||
|
|
||||||
export const createStores = () => {
|
export const createStores = () => {
|
||||||
const rows = writable([])
|
const rows = writable([])
|
||||||
const table = writable(null)
|
const table = writable(null)
|
||||||
|
@ -209,7 +211,10 @@ export const deriveStores = context => {
|
||||||
const addRow = async (row, idx, bubble = false) => {
|
const addRow = async (row, idx, bubble = false) => {
|
||||||
try {
|
try {
|
||||||
// Create row
|
// Create row
|
||||||
const newRow = await API.saveRow({ ...row, tableId: get(tableId) })
|
const newRow = await API.saveRow(
|
||||||
|
{ ...row, tableId: get(tableId) },
|
||||||
|
SuppressErrors
|
||||||
|
)
|
||||||
|
|
||||||
// Update state
|
// Update state
|
||||||
if (idx != null) {
|
if (idx != null) {
|
||||||
|
@ -336,7 +341,10 @@ export const deriveStores = context => {
|
||||||
...state,
|
...state,
|
||||||
[rowId]: true,
|
[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
|
// Update state after a successful change
|
||||||
if (saved?._id) {
|
if (saved?._id) {
|
||||||
|
|
Loading…
Reference in New Issue