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

stub of new error report data

parent 0e48a796
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"
export type ErrorData = {
url: string | null;
login: string | null;
email: string | null;
browser: string | null;
timestamp: string | null;
version: string | null;
comment: string | null;
stacktrace: string;
javaStacktrace: string | null;
};
/* eslint-disable no-console */
import { ErrorData } from '@/utils/error-report/ErrorData';
import { SerializedError } from '@reduxjs/toolkit';
export const handleError = (error: Error | SerializedError | undefined): void => {
let stacktrace = '';
if (error !== undefined) {
stacktrace = error.stack !== undefined ? error.stack : '';
}
const errorData: ErrorData = {
url: null, // TODO
login: null, // TODO provide user login
browser: null, // TODO
comment: null,
email: null, // TODO
javaStacktrace: null, // TODO
stacktrace,
timestamp: null, // TODO
version: null, // TODO
};
// eslint-disable-next-line no-console
console.log(errorData);
};
export const initializeErrorReporting = (): void => {
if (typeof window !== 'undefined') {
window.onerror = (msg, url, lineNo, columnNo, error): boolean => {
handleError(error);
return true;
};
}
};
import { getErrorMessage } from '@/utils/getErrorMessage';
import { SerializedError } from '@reduxjs/toolkit';
import { getErrorName } from '@/utils/error-report/getErrorName';
import { getErrorCode } from '@/utils/error-report/getErrorCode';
import { getErrorStack } from '@/utils/error-report/getErrorStack';
type GetErrorMessageConfig = {
error: unknown;
message?: string;
prefix?: string;
};
export const getError = ({ error, message, prefix }: GetErrorMessageConfig): SerializedError => {
const errorMessage = getErrorMessage({ error, message, prefix });
const name = getErrorName(error);
const stack = getErrorStack(error);
const code = getErrorCode(error);
return {
name,
message: errorMessage,
stack,
code,
};
};
import axios from 'axios';
import {
UNKNOWN_AXIOS_ERROR_CODE,
UNKNOWN_ERROR,
} from '../getErrorMessage/getErrorMessage.constants';
export const getErrorCode = (error: unknown): string => {
if (axios.isAxiosError(error)) {
const { code } = error;
return code || UNKNOWN_AXIOS_ERROR_CODE;
}
return UNKNOWN_ERROR;
};
import axios from 'axios';
import { UNKNOWN_ERROR } from '../getErrorMessage/getErrorMessage.constants';
export const getErrorName = (error: unknown): string => {
if (axios.isAxiosError(error)) {
return error.name;
}
if (error instanceof Error) {
return error.name;
}
return UNKNOWN_ERROR;
};
import axios from 'axios';
import { getErrorUrl } from '@/utils/error-report/getErrorUrl';
export const getErrorStack = (error: unknown): string => {
let stack = null;
if (axios.isAxiosError(error)) {
const url = getErrorUrl(error);
stack = (url ? `(Request URL: ${url}) ` : '') + error.stack;
} else if (error instanceof Error) {
stack = error.stack;
}
return stack || 'No stack provided';
};
import axios from 'axios';
export const getErrorUrl = (error: unknown): string | null => {
if (axios.isAxiosError(error)) {
if (error.request) {
if (error.request.responseURL) {
return error.request.responseURL;
}
}
}
return null;
};
export const UNKNOWN_ERROR = 'An unknown error occurred. Please try again later.'; export const UNKNOWN_ERROR = 'An unknown error occurred. Please try again later.';
export const UNKNOWN_AXIOS_ERROR_CODE = 'UNKNOWN_AXIOS_ERROR';
export const HTTP_ERROR_MESSAGES = { export const HTTP_ERROR_MESSAGES = {
400: "The server couldn't understand your request. Please check your input and try again.", 400: "The server couldn't understand your request. Please check your input and try again.",
......
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