Skip to content
Snippets Groups Projects
Commit c0098c09 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

send error report to developers

parent 357e28b9
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!199Resolve "[MIN-321] form for reporting errors in minerva"
......@@ -4,8 +4,13 @@ import { Button } from '@/shared/Button';
import { Input } from '@/shared/Input';
import React from 'react';
import { currentErrorDataSelector } from '@/redux/modal/modal.selector';
import { sendReport } from '@/utils/error-report/sendErrorReport';
import { ONE_THOUSAND } from '@/constants/common';
import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
import { closeModal } from '@/redux/modal/modal.slice';
export const ErrorReportModal: React.FC = () => {
const dispatch = useAppDispatch();
const errorData = useAppSelector(currentErrorDataSelector);
function getValue(nullableVale: string | null | undefined): string {
......@@ -24,6 +29,7 @@ export const ErrorReportModal: React.FC = () => {
const stacktrace = getValue(errorData?.stacktrace);
const version = getValue(errorData?.version);
const message = getValue(errorData?.message);
const timestamp = errorData ? errorData.timestamp : Math.floor(+new Date() / ONE_THOUSAND);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [errorDataToSend, setValue] = React.useState({
......@@ -35,6 +41,7 @@ export const ErrorReportModal: React.FC = () => {
javaStacktrace,
stacktrace,
version,
timestamp,
message,
});
......@@ -63,6 +70,8 @@ export const ErrorReportModal: React.FC = () => {
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>): Promise<void> => {
e.preventDefault();
await dispatch(sendReport(errorDataToSend));
dispatch(closeModal());
};
return (
......
......@@ -95,4 +95,5 @@ export const apiPath = {
logout: (): string => `doLogout`,
user: (login: string): string => `users/${login}`,
getStacktrace: (code: string): string => `stacktrace/${code}`,
submitError: (): string => `minervanet/submitError`,
};
import { axiosInstance } from '@/services/api/utils/axiosInstance';
import { createAsyncThunk } from '@reduxjs/toolkit';
import { Login } from '@/types/models';
import { ErrorData } from '@/utils/error-report/ErrorData';
import { apiPath } from '@/redux/apiPath';
import { showToast } from '@/utils/showToast';
export const sendReport = createAsyncThunk('error/report', async (errorData: ErrorData) => {
try {
await axiosInstance.post<Login>(apiPath.submitError(), errorData);
showToast({ type: 'success', message: 'Error report sent successfully.' });
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
showToast({
type: 'error',
message: 'Unexpected error. More information can be found in the console.',
});
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment