Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #2890
Closed
Open
Issue created May 14, 2019 by Administrator@rootContributor

[REQ] [Javascript] Repeat or copy api request

Created by: ybelenko

Is your feature request related to a problem? Please describe.

Current Javascript generator based on Superagent npm package to make Api calls. It provides option to retry http request when server doesn't respond. Ref to guide https://visionmedia.github.io/superagent/#retrying-requests

But real nightmare starts when you need to refresh access token every 15 minutes. Let's say server responds with 401 status when your access token expired.

import { UsersApi } from './api-sdk/src';

const api = new UsersApi();
api.getCurrentUser()
  .then((data) => {
    // succes, everything great
  })
  .catch((error) => {
    if (error.status === 401) {
      // obtain new success token and try again
      api.refreshToken(accessToken, refreshToken, scope)
        .then((data) => {
          // now we have valid access token and need to repeat request
          api.getCurrentUser()
            .then((data) => {
              // finally user data retrieved
            })
            .catch((error) => {
              // something completely wrong
            })
        })
        .catch((error) => {
          // maybe api server is down
        })
    }
  });

Describe the solution you'd like

I think that error instance in reject callback should contain request instance or method to call the same endpoint again. Maybe

api.getUser()
  .then((data) => {

  })
  .catch((error) => {
    const { apiRequest } = error;
    apiRequest.reset();
    apiRequest.call();
  });

Describe alternatives you've considered

or another example, but I don't know how to write it clean with promises:

const originalRequest = api.getUser();
originalRequest.call();

// when you need to repeat the same call
const clonedRequest = api.clone(originalRequest);
clonedRequest.call();

In a perfect world this issue requires some kind of middleware, I think. Middleware intercepts every failed request ended with 401 response, refreshes token and makes the same call again. Developer can write that middleware when he got option to recreate original request within error callback.

cc @jfiala @achew22 @jaypea

Assignee
Assign to
Time tracking