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 axios, { AxiosError, AxiosResponse } from 'axios';
import { LOG } from "@logger";
import axios, { type AxiosError, type AxiosResponse } from "axios";
const log = LOG.extend("AxiosRequest");
const baseUrl = process.env.EXPO_PUBLIC_API_URL;
const client = axios.create({baseURL : baseUrl});
const axiosRequest = async<T> ({...options}) : Promise<T> => {
// console.log("base Url", baseUrl);
// client.defaults.headers.common.Authorization = `Bearer ${""}`;
// client.defaults.headers.common['Content-Type'] = 'application/json';
// console.log("client default", client.defaults);
// console.log("client datas", client.defaults.data);
log.debug("RequestOptions :: ", options);
const onSuccess = (response : T) => {
return response
};
const onError = (error : AxiosError) => {
log.error(error);
throw error;
};
try {
const response : AxiosResponse<T> = await client({ ...options });
return onSuccess(response.data);
} catch (error : any) {
log.error("RequestError :: ", error);
log.error("RequestError Reponse :: ", error.response);
return onError(error);
}
}
export default axiosRequest;
\ No newline at end of file
// 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> => {
// console.log("base Url", baseUrl);
// client.defaults.headers.common.Authorization = `Bearer ${""}`;
// client.defaults.headers.common['Content-Type'] = 'application/json';
// console.log("client default", client.defaults);
// console.log("client datas", client.defaults.data);
log.debug("RequestOptions :: ", options);
const onSuccess = (response: T) => {
return response;
};
const onError = (error: AxiosError) => {
log.error(error);
throw error;
};
try {
const response: AxiosResponse<T> = await client({ ...options });
return onSuccess(response.data);
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
log.error("axiosRequest | Response :: ", JSON.stringify(error.response, null, 2));
// 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;
import { IauthenticationData } from "@/contexts/Types";
import type { IauthenticationData } from "@/contexts/Types";
import { LOG } from "@logger";
import axiosRequest from "../axios-request";
import axiosRequest from "../axiosRequest";
const log = LOG.extend("authenticateUser");
const authenticateUser = async ({ username, password }: { username: string; password: string }) => {
log.http({username, password});
log.http({ username, password });
const response = await axiosRequest<IauthenticationData>({
url: "/api/token/",
method: "POST",
......@@ -15,8 +15,7 @@ const authenticateUser = async ({ username, password }: { username: string; pass
},
});
log.http(JSON.stringify(response, null, 2));
return response
return response;
};
export default authenticateUser;
\ No newline at end of file
export default authenticateUser;
import { LOG } from "@logger";
import base64 from "react-native-base64";
import axiosRequest from "../axios-request";
import axiosRequest from "../axiosRequest";
import type { IpaginatedResponse, IpaymentType } from "./types";
const basictoken = base64.encode("admin:admin");
......
import { LOG } from "@logger";
import base64 from "react-native-base64";
import axiosRequest from "../axios-request";
import axiosRequest from "../axiosRequest";
export interface IorangePaymentStarter {
// biome-ignore lint/style/useNamingConvention: <api expect type_paiement>
......
import { LOG } from "@logger";
import base64 from "react-native-base64";
import axiosRequest from "../axios-request";
import axiosRequest from "../axiosRequest";
import type { PaymentCode } from "./types";
const log = LOG.extend("transactions");
......
import { LOG } from "@logger";
import base64 from "react-native-base64";
import axiosRequest from "../axios-request";
import axiosRequest from "../axiosRequest";
import type { IuserInformations } from "./types";
const log = LOG.extend("getUserInformations");
......
import { LOG } from "@logger";
import base64 from "react-native-base64";
import axiosRequest from "../axios-request";
import axiosRequest from "../axiosRequest";
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