[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-merchant-backoffice] 02/03: fix new typescript checks
From: |
gnunet |
Subject: |
[taler-merchant-backoffice] 02/03: fix new typescript checks |
Date: |
Mon, 29 Nov 2021 04:49:08 +0100 |
This is an automated email from the git hooks/post-receive script.
sebasjm pushed a commit to branch master
in repository merchant-backoffice.
commit ad62f32473f4b87840fa14c2a12c2257ee8414be
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Mon Nov 29 00:47:47 2021 -0300
fix new typescript checks
---
packages/merchant-backoffice/package.json | 4 ++--
.../merchant-backoffice/src/components/form/InputTaxes.tsx | 6 ++++--
.../src/components/product/NonInventoryProductForm.tsx | 6 ++++--
.../src/components/product/ProductForm.tsx | 6 ++++--
packages/merchant-backoffice/src/hooks/backend.ts | 11 +++++++++--
packages/merchant-backoffice/src/paths/admin/list/index.tsx | 4 ++--
.../src/paths/instance/orders/list/Table.tsx | 11 ++++++++---
.../src/paths/instance/reserves/list/AutorizeTipModal.tsx | 7 +++++--
.../src/paths/instance/reserves/list/index.tsx | 2 +-
9 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/packages/merchant-backoffice/package.json
b/packages/merchant-backoffice/package.json
index d800e9a..cab9797 100644
--- a/packages/merchant-backoffice/package.json
+++ b/packages/merchant-backoffice/package.json
@@ -67,7 +67,7 @@
"@storybook/preset-scss": "^1.0.3",
"@testing-library/preact": "^2.0.1",
"@testing-library/preact-hooks": "^1.1.0",
- "@types/enzyme": "^3.10.8",
+ "@types/enzyme": "^3.10.10",
"@types/history": "^4.7.8",
"@types/jest": "^26.0.23",
"@types/mocha": "^8.2.2",
@@ -84,7 +84,7 @@
"bulma-upload-control": "^1.2.0",
"dotenv": "^8.2.0",
"enzyme": "^3.11.0",
- "enzyme-adapter-preact-pure": "^3.1.0",
+ "enzyme-adapter-preact-pure": "^3.2.0",
"eslint": "^7.25.0",
"eslint-config-preact": "^1.1.4",
"eslint-plugin-header": "^3.1.1",
diff --git a/packages/merchant-backoffice/src/components/form/InputTaxes.tsx
b/packages/merchant-backoffice/src/components/form/InputTaxes.tsx
index 9c04397..507a612 100644
--- a/packages/merchant-backoffice/src/components/form/InputTaxes.tsx
+++ b/packages/merchant-backoffice/src/components/form/InputTaxes.tsx
@@ -45,8 +45,10 @@ export function InputTaxes<T>({ name, readonly, label }:
Props<keyof T>): VNode
try {
schema.validateSync(value, { abortEarly: false })
} catch (err) {
- const yupErrors = err.inner as yup.ValidationError[]
- errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev,
[cur.path]: cur.message }), {})
+ if (err instanceof yup.ValidationError) {
+ const yupErrors = err.inner as yup.ValidationError[]
+ errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev,
[cur.path]: cur.message }), {})
+ }
}
const hasErrors = Object.keys(errors).some(k => (errors as any)[k] !==
undefined)
diff --git
a/packages/merchant-backoffice/src/components/product/NonInventoryProductForm.tsx
b/packages/merchant-backoffice/src/components/product/NonInventoryProductForm.tsx
index 8aff1cd..397efe6 100644
---
a/packages/merchant-backoffice/src/components/product/NonInventoryProductForm.tsx
+++
b/packages/merchant-backoffice/src/components/product/NonInventoryProductForm.tsx
@@ -111,8 +111,10 @@ export function ProductForm({ onSubscribe, initial }:
ProductProps): VNode {
try {
schema.validateSync(value, { abortEarly: false })
} catch (err) {
- const yupErrors = err.inner as yup.ValidationError[]
- errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev,
[cur.path]: cur.message }), {})
+ if (err instanceof yup.ValidationError) {
+ const yupErrors = err.inner as yup.ValidationError[]
+ errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev,
[cur.path]: cur.message }), {})
+ }
}
const submit = useCallback((): Entity | undefined => {
diff --git
a/packages/merchant-backoffice/src/components/product/ProductForm.tsx
b/packages/merchant-backoffice/src/components/product/ProductForm.tsx
index 9e8ac97..45e70c2 100644
--- a/packages/merchant-backoffice/src/components/product/ProductForm.tsx
+++ b/packages/merchant-backoffice/src/components/product/ProductForm.tsx
@@ -65,8 +65,10 @@ export function ProductForm({ onSubscribe, initial,
alreadyExist, }: Props) {
try {
(alreadyExist ? updateSchema : createSchema).validateSync(value, {
abortEarly: false })
} catch (err) {
- const yupErrors = err.inner as yup.ValidationError[]
- errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev,
[cur.path]: cur.message }), {})
+ if (err instanceof yup.ValidationError) {
+ const yupErrors = err.inner as yup.ValidationError[]
+ errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev,
[cur.path]: cur.message }), {})
+ }
}
const hasErrors = Object.keys(errors).some(k => (errors as any)[k] !==
undefined)
diff --git a/packages/merchant-backoffice/src/hooks/backend.ts
b/packages/merchant-backoffice/src/hooks/backend.ts
index 96b8f71..344fb6a 100644
--- a/packages/merchant-backoffice/src/hooks/backend.ts
+++ b/packages/merchant-backoffice/src/hooks/backend.ts
@@ -201,6 +201,10 @@ export function setAxiosRequestAsTestingEnvironment() {
removeAxiosCancelToken = true
}
+export function isAxiosError<T>(error: AxiosError | any): error is
AxiosError<T> {
+ return error && error.isAxiosError
+}
+
export async function request<T>(url: string, options: RequestOptions = {}):
Promise<HttpResponseOk<T>> {
const headers = options.token ? { Authorization: `Bearer ${options.token}` }
: undefined
@@ -217,8 +221,11 @@ export async function request<T>(url: string, options:
RequestOptions = {}): Pro
})
return buildRequestOk<T>(res, url, !!options.token)
} catch (e) {
- const error = buildRequestFailed(e, url, !!options.token)
- throw error
+ if (isAxiosError<MerchantBackend.ErrorDetail>(e)) {
+ const error = buildRequestFailed(e, url, !!options.token)
+ throw error
+ }
+ throw e
}
}
diff --git a/packages/merchant-backoffice/src/paths/admin/list/index.tsx
b/packages/merchant-backoffice/src/paths/admin/list/index.tsx
index 2dd9c2b..f762a07 100644
--- a/packages/merchant-backoffice/src/paths/admin/list/index.tsx
+++ b/packages/merchant-backoffice/src/paths/admin/list/index.tsx
@@ -80,7 +80,7 @@ export default function Instances({ onUnauthorized,
onLoadError, onNotFound, onC
setNotif({
message: i18n`Failed to delete instance`,
type: "ERROR",
- description: error.message
+ description: error instanceof Error ? error.message : undefined
})
// pushNotification({ message: 'delete_error', type: 'ERROR' })
}
@@ -101,7 +101,7 @@ export default function Instances({ onUnauthorized,
onLoadError, onNotFound, onC
setNotif({
message: i18n`Failed to purge instance`,
type: "ERROR",
- description: error.message
+ description: error instanceof Error ? error.message : undefined
})
}
setPurging(null)
diff --git
a/packages/merchant-backoffice/src/paths/instance/orders/list/Table.tsx
b/packages/merchant-backoffice/src/paths/instance/orders/list/Table.tsx
index 50da549..58b8064 100644
--- a/packages/merchant-backoffice/src/paths/instance/orders/list/Table.tsx
+++ b/packages/merchant-backoffice/src/paths/instance/orders/list/Table.tsx
@@ -34,6 +34,7 @@ import { RefundSchema } from "../../../../schemas";
import { mergeRefunds } from "../../../../utils/amount";
import { Amounts } from "@gnu-taler/taler-util";
import { useConfigContext } from "../../../../context/config";
+import * as yup from 'yup';
type Entity = MerchantBackend.Orders.OrderHistoryEntry & WithId
interface Props {
@@ -169,9 +170,13 @@ export function RefundModal({ order, onCancel, onConfirm
}: RefundModalProps): V
reason: `${form.mainReason}: ${form.description}`
})
} catch (err) {
- const errors = err.inner as any[]
- const pathMessages = errors.reduce((prev, cur) => !cur.path ? prev : ({
...prev, [cur.path]: cur.message }), {})
- setErrors(pathMessages)
+ if (err instanceof yup.ValidationError) {
+ const errors = err.inner as any[]
+ const pathMessages = errors.reduce((prev, cur) => !cur.path ? prev :
({ ...prev, [cur.path]: cur.message }), {})
+ setErrors(pathMessages)
+ } else {
+ console.log(err)
+ }
}
}
diff --git
a/packages/merchant-backoffice/src/paths/instance/reserves/list/AutorizeTipModal.tsx
b/packages/merchant-backoffice/src/paths/instance/reserves/list/AutorizeTipModal.tsx
index a4b8af8..ec468b2 100644
---
a/packages/merchant-backoffice/src/paths/instance/reserves/list/AutorizeTipModal.tsx
+++
b/packages/merchant-backoffice/src/paths/instance/reserves/list/AutorizeTipModal.tsx
@@ -29,6 +29,7 @@ import { MerchantBackend } from "../../../../declaration";
import { useTranslator } from "../../../../i18n";
import { AuthorizeTipSchema } from "../../../../schemas";
import { CreatedSuccessfully } from "./CreatedSuccessfully";
+import * as yup from 'yup';
interface AuthorizeTipModalProps {
onCancel: () => void;
@@ -50,8 +51,10 @@ export function AuthorizeTipModal({ onCancel, onConfirm,
tipAuthorized }: Author
try {
AuthorizeTipSchema.validateSync(form, { abortEarly: false })
} catch (err) {
- const yupErrors = err.inner as any[]
- errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev,
[cur.path]: cur.message }), {})
+ if (err instanceof yup.ValidationError) {
+ const yupErrors = err.inner as any[]
+ errors = yupErrors.reduce((prev, cur) => !cur.path ? prev : ({ ...prev,
[cur.path]: cur.message }), {})
+ }
}
const hasErrors = Object.keys(errors).some(k => (errors as any)[k] !==
undefined)
diff --git
a/packages/merchant-backoffice/src/paths/instance/reserves/list/index.tsx
b/packages/merchant-backoffice/src/paths/instance/reserves/list/index.tsx
index 4c9a7df..7a1cfdb 100644
--- a/packages/merchant-backoffice/src/paths/instance/reserves/list/index.tsx
+++ b/packages/merchant-backoffice/src/paths/instance/reserves/list/index.tsx
@@ -78,7 +78,7 @@ export default function ListTips({ onUnauthorized,
onLoadError, onNotFound, onSe
setNotif({
message: i18n`could not create the tip`,
type: "ERROR",
- description: error.message
+ description: error instanceof Error ? error.message : undefined
})
setReserveForTip(undefined)
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.