mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-25 17:37:57 +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 = {
|
export const DELETE_EVENTS_DEFAULT_VALUE = {
|
||||||
eventType: '"entityDeleted"',
|
eventType: 'entityDeleted',
|
||||||
entities: ['*', 'table', 'topic', 'dashboard', 'pipeline'],
|
entities: ['*', 'table', 'topic', 'dashboard', 'pipeline'],
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError, AxiosResponse } from 'axios';
|
||||||
import { LoadingState } from 'Models';
|
import { LoadingState } from 'Models';
|
||||||
import React, { FunctionComponent, useState } from 'react';
|
import React, { FunctionComponent, useState } from 'react';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
@ -43,12 +43,16 @@ const AddWebhookPage: FunctionComponent = () => {
|
|||||||
const handleSave = (data: CreateWebhook) => {
|
const handleSave = (data: CreateWebhook) => {
|
||||||
setStatus('waiting');
|
setStatus('waiting');
|
||||||
addWebhook(data)
|
addWebhook(data)
|
||||||
.then(() => {
|
.then((res: AxiosResponse) => {
|
||||||
setStatus('success');
|
if (res.data) {
|
||||||
setTimeout(() => {
|
setStatus('success');
|
||||||
setStatus('initial');
|
setTimeout(() => {
|
||||||
goToWebhooks();
|
setStatus('initial');
|
||||||
}, 500);
|
goToWebhooks();
|
||||||
|
}, 500);
|
||||||
|
} else {
|
||||||
|
throw jsonData['api-error-messages']['unexpected-error'];
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(err, jsonData['api-error-messages']['unexpected-error']);
|
showErrorToast(err, jsonData['api-error-messages']['unexpected-error']);
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError, AxiosResponse } from 'axios';
|
||||||
import { LoadingState } from 'Models';
|
import { LoadingState } from 'Models';
|
||||||
import React, { FunctionComponent, useEffect, useState } from 'react';
|
import React, { FunctionComponent, useEffect, useState } from 'react';
|
||||||
import { useHistory, useParams } from 'react-router-dom';
|
import { useHistory, useParams } from 'react-router-dom';
|
||||||
@ -46,7 +46,11 @@ const EditWebhookPage: FunctionComponent = () => {
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
getWebhookByName(webhookName)
|
getWebhookByName(webhookName)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
setWebhookData(res.data);
|
if (res.data) {
|
||||||
|
setWebhookData(res.data);
|
||||||
|
} else {
|
||||||
|
throw jsonData['api-error-messages']['unexpected-error'];
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(err, jsonData['api-error-messages']['unexpected-error']);
|
showErrorToast(err, jsonData['api-error-messages']['unexpected-error']);
|
||||||
@ -66,12 +70,16 @@ const EditWebhookPage: FunctionComponent = () => {
|
|||||||
setStatus('waiting');
|
setStatus('waiting');
|
||||||
const { name, secretKey } = webhookData || data;
|
const { name, secretKey } = webhookData || data;
|
||||||
updateWebhook({ ...data, name, secretKey })
|
updateWebhook({ ...data, name, secretKey })
|
||||||
.then(() => {
|
.then((res: AxiosResponse) => {
|
||||||
setStatus('success');
|
if (res.data) {
|
||||||
setTimeout(() => {
|
setStatus('success');
|
||||||
setStatus('initial');
|
setTimeout(() => {
|
||||||
goToWebhooks();
|
setStatus('initial');
|
||||||
}, 500);
|
goToWebhooks();
|
||||||
|
}, 500);
|
||||||
|
} else {
|
||||||
|
throw jsonData['api-error-messages']['unexpected-error'];
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(err, jsonData['api-error-messages']['unexpected-error']);
|
showErrorToast(err, jsonData['api-error-messages']['unexpected-error']);
|
||||||
@ -82,9 +90,13 @@ const EditWebhookPage: FunctionComponent = () => {
|
|||||||
const handleDelete = (id: string) => {
|
const handleDelete = (id: string) => {
|
||||||
setDeleteStatus('waiting');
|
setDeleteStatus('waiting');
|
||||||
deleteWebhook(id)
|
deleteWebhook(id)
|
||||||
.then(() => {
|
.then((res: AxiosResponse) => {
|
||||||
setDeleteStatus('initial');
|
if (res.data) {
|
||||||
goToWebhooks();
|
setDeleteStatus('initial');
|
||||||
|
goToWebhooks();
|
||||||
|
} else {
|
||||||
|
throw jsonData['api-error-messages']['unexpected-error'];
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError) => {
|
.catch((err: AxiosError) => {
|
||||||
showErrorToast(err, jsonData['api-error-messages']['unexpected-error']);
|
showErrorToast(err, jsonData['api-error-messages']['unexpected-error']);
|
||||||
|
@ -134,6 +134,23 @@ describe('Test DatasetDetails page', () => {
|
|||||||
expect(addWebhookComponent).toBeInTheDocument();
|
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 () => {
|
it('Show error message on failing of deleteWebhook api', async () => {
|
||||||
(deleteWebhook as jest.Mock).mockImplementationOnce(() =>
|
(deleteWebhook as jest.Mock).mockImplementationOnce(() =>
|
||||||
Promise.reject({
|
Promise.reject({
|
||||||
@ -150,5 +167,22 @@ describe('Test DatasetDetails page', () => {
|
|||||||
|
|
||||||
expect(addWebhookComponent).toBeInTheDocument();
|
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