َحیشفثی
This commit is contained in:
@@ -290,7 +290,7 @@ const handleSubmit = (withValidation: boolean) => {
|
||||
</DataField>
|
||||
<DataField
|
||||
id="personal-data-birth-date"
|
||||
label="تاریخ تولد"
|
||||
label="تاریsخ تولد"
|
||||
:error="formValidator$.birth_date"
|
||||
>
|
||||
<Datepicker
|
||||
|
||||
@@ -1,24 +1,18 @@
|
||||
import axiosOriginal from "axios";
|
||||
import { useAuth } from "~/composables/api/auth/useAuth";
|
||||
import { API_ENDPOINTS } from "~/constants";
|
||||
import Logger from "~/tools/logger";
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const config = useRuntimeConfig();
|
||||
const { token } = useAuth();
|
||||
|
||||
const axios = axiosOriginal.create({
|
||||
baseURL: config.public.API_BASE_URL
|
||||
baseURL: config.public.API_BASE_URL,
|
||||
});
|
||||
|
||||
axios.interceptors.request.use((config) => {
|
||||
if (
|
||||
!config.url?.includes(API_ENDPOINTS.auth.signin) &&
|
||||
!config.url?.includes(API_ENDPOINTS.account.send_otp)
|
||||
) {
|
||||
config.headers.Authorization = token.value
|
||||
? `Bearer ${token.value}`
|
||||
: undefined;
|
||||
if (!config.url?.includes(API_ENDPOINTS.auth.signin) && !config.url?.includes(API_ENDPOINTS.account.send_otp)) {
|
||||
config.headers.Authorization = token.value ? `Bearer ${token.value}` : undefined;
|
||||
}
|
||||
|
||||
return config;
|
||||
@@ -28,19 +22,14 @@ export default defineNuxtPlugin(() => {
|
||||
(response) => {
|
||||
return response;
|
||||
},
|
||||
async function(error) {
|
||||
|
||||
if (config.public.DEBUG === "true" && import.meta.server) {
|
||||
await Logger.axiosErrorLog(error);
|
||||
}
|
||||
|
||||
async function (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
provide: {
|
||||
axios
|
||||
}
|
||||
axios,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
// Also possible
|
||||
nuxtApp.hook('vue:error', (error, instance, info) => {
|
||||
// handle error, e.g. report to a service
|
||||
})
|
||||
})
|
||||
@@ -1,40 +0,0 @@
|
||||
import fs from "fs/promises";
|
||||
import { ensureFileExists } from "~/utils";
|
||||
|
||||
class Logger {
|
||||
public static async axiosErrorLog(error: any) {
|
||||
const errorJson = error.toJSON();
|
||||
|
||||
const nowDate = new Date();
|
||||
|
||||
const logData: AxiosLogType = {
|
||||
url: errorJson.config.url,
|
||||
code: errorJson.code!,
|
||||
status: errorJson.status!,
|
||||
method: errorJson.config.method,
|
||||
response: error?.response?.data,
|
||||
requestHeaders: errorJson.config.headers,
|
||||
// responseHeaders: error.response.headers,
|
||||
payload: errorJson.config.data ? JSON.parse(errorJson.config.data) : undefined,
|
||||
params: errorJson.config.params ?? undefined,
|
||||
date: nowDate.toString()
|
||||
};
|
||||
|
||||
const logFilePath = ".logs/log.json";
|
||||
|
||||
try {
|
||||
await ensureFileExists(logFilePath, "[]");
|
||||
|
||||
const oldLogs = await fs.readFile(logFilePath, "utf-8");
|
||||
const oldLogsJson = JSON.parse(oldLogs) as Record<any, any>[];
|
||||
|
||||
oldLogsJson.push(logData);
|
||||
|
||||
await fs.writeFile(logFilePath, JSON.stringify(oldLogsJson, null, 2));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Logger;
|
||||
Reference in New Issue
Block a user