Commit bbb27f23 by G

print a json representation of the error response. Also i changed the name of…

print a json representation of the error response. Also i changed the name of the file to follow naming convention
parent 0d5b050c
import { LOG } from '@logger'; import { LOG } from "@logger";
import axios, { AxiosError, AxiosResponse } from 'axios'; import axios, { type AxiosError, type AxiosResponse } from "axios";
const log = LOG.extend("AxiosRequest"); const log = LOG.extend("AxiosRequest");
const baseUrl = process.env.EXPO_PUBLIC_API_URL; const baseUrl = process.env.EXPO_PUBLIC_API_URL;
const client = axios.create({baseURL : baseUrl}); // biome-ignore lint/style/useNamingConvention: <baseURL is not for me to change.>
const client = axios.create({ baseURL: baseUrl });
const axiosRequest = async<T> ({...options}) : Promise<T> => { const axiosRequest = async <T>({ ...options }): Promise<T> => {
// console.log("base Url", baseUrl); // console.log("base Url", baseUrl);
// client.defaults.headers.common.Authorization = `Bearer ${""}`; // client.defaults.headers.common.Authorization = `Bearer ${""}`;
// client.defaults.headers.common['Content-Type'] = 'application/json'; // client.defaults.headers.common['Content-Type'] = 'application/json';
...@@ -17,23 +16,28 @@ const axiosRequest = async<T> ({...options}) : Promise<T> => { ...@@ -17,23 +16,28 @@ const axiosRequest = async<T> ({...options}) : Promise<T> => {
// console.log("client datas", client.defaults.data); // console.log("client datas", client.defaults.data);
log.debug("RequestOptions :: ", options); log.debug("RequestOptions :: ", options);
const onSuccess = (response: T) => {
const onSuccess = (response : T) => { return response;
return response
}; };
const onError = (error : AxiosError) => { const onError = (error: AxiosError) => {
log.error(error); log.error(error);
throw error; throw error;
}; };
try { try {
const response : AxiosResponse<T> = await client({ ...options }); const response: AxiosResponse<T> = await client({ ...options });
return onSuccess(response.data); return onSuccess(response.data);
} catch (error : any) { } catch (error: unknown) {
log.error("RequestError :: ", error); if (axios.isAxiosError(error)) {
log.error("RequestError Reponse :: ", error.response); log.error("axiosRequest | Response :: ", JSON.stringify(error.response, null, 2));
return onError(error); // log.error("Axios RequestError Reponse message:: ", error.message);
// log.error("Axios RequestError Reponse name:: ", error.response?.data);
} else {
log.error("axiosRequest | General RequestError :: ", error);
}
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
return onError(error as any);
} }
} };
export default axiosRequest; export default axiosRequest;
import { IauthenticationData } from "@/contexts/Types"; import type { IauthenticationData } from "@/contexts/Types";
import { LOG } from "@logger"; import { LOG } from "@logger";
import axiosRequest from "../axios-request"; import axiosRequest from "../axiosRequest";
const log = LOG.extend("authenticateUser"); const log = LOG.extend("authenticateUser");
const authenticateUser = async ({ username, password }: { username: string; password: string }) => { const authenticateUser = async ({ username, password }: { username: string; password: string }) => {
log.http({username, password}); log.http({ username, password });
const response = await axiosRequest<IauthenticationData>({ const response = await axiosRequest<IauthenticationData>({
url: "/api/token/", url: "/api/token/",
method: "POST", method: "POST",
...@@ -15,8 +15,7 @@ const authenticateUser = async ({ username, password }: { username: string; pass ...@@ -15,8 +15,7 @@ const authenticateUser = async ({ username, password }: { username: string; pass
}, },
}); });
log.http(JSON.stringify(response, null, 2)); log.http(JSON.stringify(response, null, 2));
return response return response;
}; };
export default authenticateUser; export default authenticateUser;
import { LOG } from "@logger"; import { LOG } from "@logger";
import base64 from "react-native-base64"; import base64 from "react-native-base64";
import axiosRequest from "../axios-request"; import axiosRequest from "../axiosRequest";
import type { IpaginatedResponse, IpaymentType } from "./types"; import type { IpaginatedResponse, IpaymentType } from "./types";
const basictoken = base64.encode("admin:admin"); const basictoken = base64.encode("admin:admin");
......
import { LOG } from "@logger"; import { LOG } from "@logger";
import base64 from "react-native-base64"; import base64 from "react-native-base64";
import axiosRequest from "../axios-request"; import axiosRequest from "../axiosRequest";
export interface IorangePaymentStarter { export interface IorangePaymentStarter {
// biome-ignore lint/style/useNamingConvention: <api expect type_paiement> // biome-ignore lint/style/useNamingConvention: <api expect type_paiement>
......
import { LOG } from "@logger"; import { LOG } from "@logger";
import base64 from "react-native-base64"; import base64 from "react-native-base64";
import axiosRequest from "../axios-request"; import axiosRequest from "../axiosRequest";
import type { PaymentCode } from "./types"; import type { PaymentCode } from "./types";
const log = LOG.extend("transactions"); const log = LOG.extend("transactions");
......
import { LOG } from "@logger"; import { LOG } from "@logger";
import base64 from "react-native-base64"; import base64 from "react-native-base64";
import axiosRequest from "../axios-request"; import axiosRequest from "../axiosRequest";
import type { IuserInformations } from "./types"; import type { IuserInformations } from "./types";
const log = LOG.extend("getUserInformations"); const log = LOG.extend("getUserInformations");
......
import { LOG } from "@logger"; import { LOG } from "@logger";
import base64 from "react-native-base64"; import base64 from "react-native-base64";
import axiosRequest from "../axios-request"; import axiosRequest from "../axiosRequest";
const log = LOG.extend("wavePayment"); const log = LOG.extend("wavePayment");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment