How to use umi-request - 10 common examples

To help you get started, we’ve selected a few umi-request examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FE-Kits / m-fe-rtw / packages / rtw-host-app / src / skeleton / apis / umi / request.ts View on Github external
description: '您的网络发生异常,无法连接服务器',
        message: '网络异常',
      });
    }
  } catch (ie) {
    notification.error({
      description: '响应数据异常',
      message: '服务器异常',
    });
  }

  return response;
};

/** 配置 request 请求时的默认参数 */
export let umiRequest = extend({
  errorHandler, // 默认错误处理
  credentials: 'same-origin', // 默认请求是否带上cookie
});

/** 动态设置请求头 */
export function setRequestHeader(headers: Record) {
  umiRequest = extend({
    errorHandler, // 默认错误处理
    headers,
    credentials: 'same-origin', // 默认请求是否带上cookie
  });
}
github tangtanglove / fullstack-frontend / src / utils / request.ts View on Github external
description: errorText,
      });
      router.push('/exception/403');
    } else {
      notification.error({
        message: `请求错误 ${status}: ${url}`,
        description: errorText,
      });
    }
  }
};

/**
 * 配置request请求时的默认参数
 */
const request = extend({
  errorHandler, // 默认错误处理
  credentials: 'include', // 默认请求是否带上cookie
});

request.interceptors.request.use((url, options) => {
  options.headers = {
    ...options.headers,
    'Authorization': `Bearer ${sessionStorage.getItem('token')}`
  }
  return (
    {
      url: `${url}`,
      options: {
        ...options,
        interceptors: true,
      },
github ant-design / ant-design-pro-layout / example / src / utils / request.ts View on Github external
const { response } = error;
  if (response && response.status) {
    const errorText = codeMessage[response.status] || response.statusText;
    const { status, url } = response;

    notification.error({
      message: `请求错误 ${status}: ${url}`,
      description: errorText,
    });
  }
};

/**
 * 配置request请求时的默认参数
 */
const request = extend({
  errorHandler, // 默认错误处理
  credentials: 'include', // 默认请求是否带上cookie
});

export default request;
github t880216t / IAT / src / utils / request.js View on Github external
const errorHandlerRe = response => {

  if (response && response.status) {
    const errorText = codeMessage[response.status] || response.statusText;
    const { status, url } = response;
    notification.error({
      message: `请求错误 ${status}: ${url}`,
      description: errorText,
    });
  }
};
/**
 * 配置request请求时的默认参数
 */

const request = extend({
  errorHandler,
  // 默认错误处理
  credentials: 'include', // 默认请求是否带上cookie
});

// 返回值统一处理
request.interceptors.response.use(async response => {
  if (response.status >= 400) {
    errorHandlerRe(response);
  }
  const data = await response.clone().json();
  if (data && data.code === 10001) {
    message.config({
      top: '15%',
    });
    message.error(data.msg);
github hyperledger / cello / src / dashboard / src / utils / request.js View on Github external
});
  // environment should not be used
  if (status === 403) {
    router.push('/exception/403');
    return;
  }
  if (status <= 504 && status >= 500) {
    router.push('/exception/500');
    return;
  }
  if (status >= 404 && status < 422) {
    router.push('/exception/404');
  }
};

const request = extend({
  errorHandler,
  credentials: 'include',
  headers: {
    Authorization: `JWT ${localStorage.getItem('cello-token')}`,
  },
});

export default request;
github XiaoMi / thain / thain-fe / src / utils / request.ts View on Github external
*/
const errorHandler = (error: ResponseError) => {
  const { response = {} as Response } = error;
  const errortext = codeMessage[response.status] || response.statusText;
  const { status, url } = response;

  notification.error({
    message: `请求错误 ${status}: ${url}`,
    description: errortext,
  });
};

/**
 * 配置request请求时的默认参数
 */
const request = extend({
  errorHandler, // 默认错误处理
  credentials: 'include', // 默认请求是否带上cookie
});

export default request;

function statusHandler(status: number, message: string) {
  if (status !== 200) {
    notification.error({
      message: status + ': ' + message,
    });
    return true;
  }
  return false;
}
github vellengs / nestx / packages / react / src / utils / request.ts View on Github external
* 异常处理程序
 */
export const errorHandler = (error: ResponseError) => {
  const { response = {} as Response } = error;
  const errorText = codeMessage[response.status] || response.statusText;
  const { status } = response;
  notification.error({
    message: `请求错误 ${status}:`,
    description: errorText,
  });
};

/**
 * 配置request请求时的默认参数
 */
const request = extend({
  errorHandler, // 默认错误处理
  credentials: 'include', // 默认请求是否带上cookie
});

export default request;
github oam-dev / kubevela / dashboard / src / utils / request.js View on Github external
const errorHandler = async (error) => {
  const { response } = error;
  if (response && response.status) {
    const errorText = codeMessage[response.status] || response.statusText;
    const { status, url } = response;
    message.error(`请求错误 ${status}:${url} ${errorText}`);
  } else if (!response) {
    message.error('网络异常: 您的网络发生异常,无法连接服务器');
  }
};

/**
 * 配置request请求时的默认参数
 */
const request = extend({
  errorHandler, // 默认错误处理
  credentials: 'include', // 默认请求是否带上cookie
});

/*
 *  1) code == 500
 *     data 为报错字符串
 *  2) code == 200
 *     如果 method = Get,data 类型 =  list/json
 *     否则,data 类型 =  string,存储的是操作成功的信息
 */
request.interceptors.response.use(async (response) => {
  if (response.status !== 200 && response.status !== 500) {
    errorHandler({ response });
    return;
  }
github webclipper / web-clipper / src / service / config / browser / configService.ts View on Github external
load = async () => {
    try {
      if (process.env.NODE_ENV !== 'development') {
        this.config = await request.get(`${config.resourceHost}/config.json`);
      }
      runInAction(() => {
        this.isLatestVersion = !hasUpdate(this.config.chromeWebStoreVersion, this.localVersion);
      });
      const iconsFile = await request.get(this.config.iconfont);
      const matchResult: string[] = iconsFile.match(/id="([A-Za-z]+)"/g) || [];
      const remoteIcons = matchResult.map(o => o.match(/id="([A-Za-z]+)"/)![1]);
      runInAction(() => {
        remoteIcons.forEach(icon => {
          this.remoteIconSet.add(icon);
        });
      });
    } catch (_error) {
      console.log('Load Config Error');
    }
  };
github webclipper / web-clipper / src / service / config / browser / configService.ts View on Github external
load = async () => {
    try {
      if (process.env.NODE_ENV !== 'development') {
        this.config = await request.get(`${config.resourceHost}/config.json`);
      }
      runInAction(() => {
        this.isLatestVersion = !hasUpdate(this.config.chromeWebStoreVersion, this.localVersion);
      });
      const iconsFile = await request.get(this.config.iconfont);
      const matchResult: string[] = iconsFile.match(/id="([A-Za-z]+)"/g) || [];
      const remoteIcons = matchResult.map(o => o.match(/id="([A-Za-z]+)"/)![1]);
      runInAction(() => {
        remoteIcons.forEach(icon => {
          this.remoteIconSet.add(icon);
        });
      });
    } catch (_error) {
      console.log('Load Config Error');
    }
  };

umi-request

A request tool based on fetch.

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Popular umi-request functions

Similar packages