Have historyWatch report errors via notifyError instead of an onError callback.
This commit is contained in:
@@ -110,10 +110,9 @@ export class ApiClient {
|
|||||||
history: (sku) => this.#json('GET', `/api/article/${enc(sku)}/history`),
|
history: (sku) => this.#json('GET', `/api/article/${enc(sku)}/history`),
|
||||||
/**
|
/**
|
||||||
* Load history and refetch on SSE `article-<sku>`.
|
* Load history and refetch on SSE `article-<sku>`.
|
||||||
* `onHistory(history)` / `onError(err)` — returns unwatch().
|
* `onHistory(history)` — returns unwatch(). Errors via notifyError.
|
||||||
*/
|
*/
|
||||||
historyWatch: (sku, onHistory, onError) =>
|
historyWatch: (sku, onHistory) => this.watchArticleHistory(sku, onHistory),
|
||||||
this.watchArticleHistory(sku, onHistory, onError),
|
|
||||||
/** PATCH /api/article/{sku} — body: at least one of { name, unitamount, unitSi } */
|
/** PATCH /api/article/{sku} — body: at least one of { name, unitamount, unitSi } */
|
||||||
update: async (sku, body) => {
|
update: async (sku, body) => {
|
||||||
const nameChange = body != null && Object.hasOwn(body, 'name');
|
const nameChange = body != null && Object.hasOwn(body, 'name');
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { requireArray, requireDefined, requireObject } from '../utils/apiShape';
|
import { requireArray, requireDefined, requireObject } from '../utils/apiShape';
|
||||||
|
import { notifyError } from '../utils/notify';
|
||||||
import { ApiClient } from './ApiClient';
|
import { ApiClient } from './ApiClient';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,10 +85,9 @@ export class StorageManager extends ApiClient {
|
|||||||
* Fetch article history, then refetch whenever SSE emits `article-<sku>`.
|
* Fetch article history, then refetch whenever SSE emits `article-<sku>`.
|
||||||
* @param {string} sku
|
* @param {string} sku
|
||||||
* @param {(history: unknown[]) => void} onHistory
|
* @param {(history: unknown[]) => void} onHistory
|
||||||
* @param {(err: unknown) => void} onError
|
|
||||||
* @returns {() => void} unwatch
|
* @returns {() => void} unwatch
|
||||||
*/
|
*/
|
||||||
watchArticleHistory(sku, onHistory, onError) {
|
watchArticleHistory(sku, onHistory) {
|
||||||
const key = String(sku);
|
const key = String(sku);
|
||||||
let active = true;
|
let active = true;
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ export class StorageManager extends ApiClient {
|
|||||||
const run = () =>
|
const run = () =>
|
||||||
void refresh().catch((err) => {
|
void refresh().catch((err) => {
|
||||||
if (!active) return;
|
if (!active) return;
|
||||||
onError(err);
|
notifyError(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
let watchers = this.#historyWatchers.get(key);
|
let watchers = this.#historyWatchers.get(key);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import TableCell from '@mui/material/TableCell';
|
|||||||
import TableHead from '@mui/material/TableHead';
|
import TableHead from '@mui/material/TableHead';
|
||||||
import TableRow from '@mui/material/TableRow';
|
import TableRow from '@mui/material/TableRow';
|
||||||
import { StorageManagerContext } from '../../../api/storageManagerContext';
|
import { StorageManagerContext } from '../../../api/storageManagerContext';
|
||||||
import { notifyError } from '../../../utils/notify';
|
|
||||||
|
|
||||||
function formatDate(iso) {
|
function formatDate(iso) {
|
||||||
return new Date(iso).toLocaleString('de-DE');
|
return new Date(iso).toLocaleString('de-DE');
|
||||||
@@ -24,7 +23,6 @@ export default class ArticleHistoryTab extends Component {
|
|||||||
this.unwatchHistory = this.context.article.historyWatch(
|
this.unwatchHistory = this.context.article.historyWatch(
|
||||||
this.props.sku,
|
this.props.sku,
|
||||||
(history) => this.setState({ history }),
|
(history) => this.setState({ history }),
|
||||||
notifyError,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user