Is it possible to convert this JS code into .NET?

I really need help and i would apreciate if someone can help me with this I need to do the same than here but with .NET, instead of node js. I never worked with .NET before.

Question: Is it possible to do this with .NET? if it’s not possible, i would like to know it. thanks.

UH API Behavior - Error handling
. Sample API request with retry for refreshing the token (if the app is using axios and MSAL.js).

get: async (url, retry = true) => {
        const _url = url;
        const headers = {
            Authorization: `Bearer ${sessionStorage.getItem("user_token")}`
        };
        const _retry = retry;

        const axiosInstance = axios.create({
            headers,
            responseType: "application/json"

        });
        axiosInstance.interceptors.response.use(

            (res) => {                return res;
            },
            async (error) => {

                // debugger;
                const status = error.response ? error.response.status : null;
                if (status === 401 && _retry) {
                    sessionStorage.removeItem("user_token");
              const hasToken = await  refreshToken();        
         
                        return httpClirefreshTokenentServiceWithRefreshToken.get(
                            _url,
                            false
                        );                   
                }
                return Promise.reject(error);
            }
        );
        return new Promise((resolve, reject) => {
            axiosInstance
                .get(_url)
                // .post(url, data, headers)
                .then((response) => {
                    if (response.status === 200) {
                        resolve(response.data);
                    } else {
                        resolve(response);
                    }
                })
                .catch((e) => {
                    reject(e);
                });
        });
    },

We’re going to keep this in one place to ensure the best shot you have of getting an answer. .net seems like the better place for it, so I’m going to close this one.

THREAD CLOSED

1 Like