Skip to content

Commit

Permalink
usePromise ability to report to rollbar
Browse files Browse the repository at this point in the history
5.2.15
  • Loading branch information
arietrouw committed Oct 31, 2024
1 parent 62bf74c commit b33e5ec
Show file tree
Hide file tree
Showing 35 changed files with 206 additions and 53 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/sdk-react",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down Expand Up @@ -116,6 +116,7 @@
"buffer": "^6.0.3",
"eslint": "^9.13.0",
"eslint-import-resolver-typescript": "^3.6.3",
"knip": "^5.34.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"remark-gfm": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/accordion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-accordion",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/animation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-animation",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
6 changes: 1 addition & 5 deletions packages/app-settings/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-app-settings",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down Expand Up @@ -37,10 +37,6 @@
},
"module": "dist/browser/index.mjs",
"types": "dist/browser/index.d.ts",
"scripts": {
"license": "yarn license-checker --exclude \"MIT, ISC, Apache-2.0, BSD, BSD-2-Clause, CC-BY-4.0, Unlicense, CC-BY-3.0, CC0-1.0\"",
"lint-pkg": "npmPkgJsonLint ."
},
"dependencies": {
"@xylabs/assert": "^4.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/appbar/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-appbar",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/async-effect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-async-effect",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/base-page/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-base-page",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/button/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-button",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-common",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/cookie-consent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-cookie-consent",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-crypto",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/dialogs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-dialogs",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/error/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-error",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/experiments/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-experiments",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/flexbox/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-flexbox",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-hooks",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/identicon/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-identicon",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/invertible-theme/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-invertible-theme",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
4 changes: 2 additions & 2 deletions packages/link/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-link",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down Expand Up @@ -44,7 +44,7 @@
"@mui/material": "^6.1.6",
"@storybook/react": "^8.3.6",
"@types/react": "^18.3.12",
"@xylabs/react-flexbox": "^5.2.14",
"@xylabs/react-flexbox": "^5.2.15",
"@xylabs/react-pixel": "workspace:^",
"@xylabs/ts-scripts-yarn3": "^4.2.3",
"@xylabs/tsconfig-react": "^4.2.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/mixpanel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-mixpanel",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/number-status/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-number-status",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/pixel-debugger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-pixel-debugger",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/pixel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-pixel",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/portal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-portal",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
3 changes: 2 additions & 1 deletion packages/promise/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-promise",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down Expand Up @@ -48,6 +48,7 @@
"@xylabs/tsconfig-react": "^4.2.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rollbar": "^2.26.4",
"storybook": "^8.3.6",
"typescript": "^5.6.3"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/promise/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type Rollbar from 'rollbar'

declare global {
var rollbar: Rollbar
}
17 changes: 13 additions & 4 deletions packages/promise/src/usePromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const usePromise = <TResult>(
dependencies: DependencyList,
config?: UsePromiseConfig<TResult>,
): [TResult | undefined, Error | undefined, UsePromiseState | undefined] => {
const { logErrors } = usePromiseSettings()
const { logErrors = true } = usePromiseSettings()
const [result, setResult] = useState<TResult | undefined>(config?.defaultValue)
const [error, setError] = useState<Error>()
const [state, setState] = useState<UsePromiseState>('pending')
Expand All @@ -45,7 +45,10 @@ export const usePromise = <TResult>(
return promise?.()
} catch (ex) {
const error = ex as Error
if (logErrors) console.error(`usePromise-memo: ${error}`)
if (logErrors) {
console.error(`usePromise-memo: ${error}`)
rollbar?.error(error)
}
if (config?.debug) console.log(`usePromise [${config?.debug}]: useMemo rejection [${typeof promise}]`)
setResult(undefined)
setError(error)
Expand Down Expand Up @@ -73,7 +76,10 @@ export const usePromise = <TResult>(
})
.catch((e) => {
const error = e as Error
console.error(`usePromise: ${error.message}`)
if (logErrors) {
console.error(error)
rollbar?.error(error)
}
if (loaded) {
setResult(undefined)
setError(error)
Expand All @@ -84,7 +90,10 @@ export const usePromise = <TResult>(
})
.catch((ex) => {
const error = ex as Error
if (logErrors) console.error(`usePromise-memo: ${error}`)
if (logErrors) {
console.error(`usePromise-memo: ${error}`)
rollbar?.error(error)
}
if (loaded) {
setResult(undefined)
setError(error)
Expand Down
2 changes: 1 addition & 1 deletion packages/quick-tip-button/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-quick-tip-button",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/render-spin-check/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-render-spin-check",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/rich-result/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-rich-result",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/scroll-to-top/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-scroll-to-top",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/select/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-select",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-shared",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down
6 changes: 1 addition & 5 deletions packages/webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/react-webapp",
"version": "5.2.14",
"version": "5.2.15",
"description": "Common React library for all XY Labs projects that use React",
"keywords": [
"utility",
Expand Down Expand Up @@ -37,10 +37,6 @@
},
"module": "dist/browser/index.mjs",
"types": "dist/browser/index.d.ts",
"scripts": {
"license": "yarn license-checker --exclude \"MIT, ISC, Apache-2.0, BSD, BSD-2-Clause, CC-BY-4.0, Unlicense, CC-BY-3.0, CC0-1.0\"",
"lint-pkg": "npmPkgJsonLint ."
},
"dependencies": {
"@mui/icons-material": "^6.1.6",
"@mui/material": "^6.1.6",
Expand Down
Loading

0 comments on commit b33e5ec

Please sign in to comment.