mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-25 01:18:14 +00:00
fixed issue: Error handling not present for add/delete/update Webhook (#5911)
This commit is contained in:
parent
ba725b81e7
commit
0b5b536461
@ -22,6 +22,6 @@ export const UPDATE_EVENTS_DEFAULT_VALUE = {
|
||||
};
|
||||
|
||||
export const DELETE_EVENTS_DEFAULT_VALUE = {
|
||||
eventType: '"entityDeleted"',
|
||||
eventType: 'entityDeleted',
|
||||
entities: ['*', 'table', 'topic', 'dashboard', 'pipeline'],
|
||||
};
|
||||
|
@ -11,7 +11,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AxiosError } from 'axios';
|
||||
import { AxiosError, AxiosResponse } from 'axios';
|
||||
import { LoadingState } from 'Models';
|
||||
import React, { FunctionComponent, useState } from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
@ -43,12 +43,16 @@ const AddWebhookPage: FunctionComponent = () => {
|
||||
const handleSave = (data: CreateWebhook) => {
|
||||
setStatus('waiting');
|
||||
addWebhook(data)
|
||||
.then(() => {
|
||||
setStatus('success');
|
||||
setTimeout(() => {
|
||||
setStatus('initial');
|
||||
goToWebhooks();
|
||||
}, 500);
|
||||
.then((res: AxiosResponse) => {
|
||||
if (res.data) {
|
||||
setStatus('success');
|
||||
setTimeout(() => {
|
||||
setStatus('initial');
|
||||
goToWebhooks();
|
||||
}, 500);
|
||||
} else {
|
||||
throw jsonData['api-error-messages']['unexpected-error'];
|
||||
}
|
||||
})
|
||||
.catch((err: AxiosError) => {
|
||||
showErrorToast(err, jsonData['api-error-messages']['unexpected-error']);
|
||||
|
@ -11,7 +11,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AxiosError } from 'axios';
|
||||
import { AxiosError, AxiosResponse } from 'axios';
|
||||
import { LoadingState } from 'Models';
|
||||
import React, { FunctionComponent, useEffect, useState } from 'react';
|
||||
import { useHistory, useParams } from 'react-router-dom';
|
||||
@ -46,7 +46,11 @@ const EditWebhookPage: FunctionComponent = () => {
|
||||
setIsLoading(true);
|
||||
getWebhookByName(webhookName)
|
||||
.then((res) => {
|
||||
setWebhookData(res.data);
|
||||
if (res.data) {
|
||||
setWebhookData(res.data);
|
||||
} else {
|
||||
throw jsonData['api-error-messages']['unexpected-error'];
|
||||
}
|
||||
})
|
||||
.catch((err: AxiosError) => {
|
||||
showErrorToast(err, jsonData['api-error-messages']['unexpected-error']);
|
||||
@ -66,12 +70,16 @@ const EditWebhookPage: FunctionComponent = () => {
|
||||
setStatus('waiting');
|
||||
const { name, secretKey } = webhookData || data;
|
||||
updateWebhook({ ...data, name, secretKey })
|
||||
.then(() => {
|
||||
setStatus('success');
|
||||
setTimeout(() => {
|
||||
setStatus('initial');
|
||||
goToWebhooks();
|
||||
}, 500);
|
||||
.then((res: AxiosResponse) => {
|
||||
if (res.data) {
|
||||
setStatus('success');
|
||||
setTimeout(() => {
|
||||
setStatus('initial');
|
||||
goToWebhooks();
|
||||
}, 500);
|
||||
} else {
|
||||
throw jsonData['api-error-messages']['unexpected-error'];
|
||||
}
|
||||
})
|
||||
.catch((err: AxiosError) => {
|
||||
showErrorToast(err, jsonData['api-error-messages']['unexpected-error']);
|
||||
@ -82,9 +90,13 @@ const EditWebhookPage: FunctionComponent = () => {
|
||||
const handleDelete = (id: string) => {
|
||||
setDeleteStatus('waiting');
|
||||
deleteWebhook(id)
|
||||
.then(() => {
|
||||
setDeleteStatus('initial');
|
||||
goToWebhooks();
|
||||
.then((res: AxiosResponse) => {
|
||||
if (res.data) {
|
||||
setDeleteStatus('initial');
|
||||
goToWebhooks();
|
||||
} else {
|
||||
throw jsonData['api-error-messages']['unexpected-error'];
|
||||
}
|
||||
})
|
||||
.catch((err: AxiosError) => {
|
||||
showErrorToast(err, jsonData['api-error-messages']['unexpected-error']);
|
||||
|
@ -134,6 +134,23 @@ describe('Test DatasetDetails page', () => {
|
||||
expect(addWebhookComponent).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('Show error message on empty response of getWebhookByName api', async () => {
|
||||
(getWebhookByName as jest.Mock).mockImplementationOnce(() =>
|
||||
Promise.resolve({
|
||||
response: { data: '' },
|
||||
})
|
||||
);
|
||||
const { container } = render(<EditWebhookPage />, {
|
||||
wrapper: MemoryRouter,
|
||||
});
|
||||
const addWebhookComponent = await findByText(
|
||||
container,
|
||||
/AddWebhookComponent/i
|
||||
);
|
||||
|
||||
expect(addWebhookComponent).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('Show error message on failing of deleteWebhook api', async () => {
|
||||
(deleteWebhook as jest.Mock).mockImplementationOnce(() =>
|
||||
Promise.reject({
|
||||
@ -150,5 +167,22 @@ describe('Test DatasetDetails page', () => {
|
||||
|
||||
expect(addWebhookComponent).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('Show error message on on empty response of deleteWebhook api', async () => {
|
||||
(deleteWebhook as jest.Mock).mockImplementationOnce(() =>
|
||||
Promise.resolve({
|
||||
response: { data: '' },
|
||||
})
|
||||
);
|
||||
const { container } = render(<EditWebhookPage />, {
|
||||
wrapper: MemoryRouter,
|
||||
});
|
||||
const addWebhookComponent = await findByText(
|
||||
container,
|
||||
/AddWebhookComponent/i
|
||||
);
|
||||
|
||||
expect(addWebhookComponent).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user