Is it possible to do this node.js code with .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.

Is my first time working with tokens and APIs. So i kinda need help with this

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);
                    }
                })
           

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

It is pretty typical on here for people to share a codepen / repl.it / jsfiddle example of what they have tried so that anyone helping has more of an idea of what help is actually helpful.

Please provide some example of what you’ve tried and I’m sure you’ll get more help.

Happy coding :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.