Skip to content
Snippets Groups Projects
Select Git revision
  • 99e1c17935af0275d7509fa52256a394848ed47b
  • test default protected
  • master protected
  • original
  • pirati-backup protected
  • beta-2
  • beta-1
  • v3.1.4
  • v3.1.3
  • v3.1.2
  • v3.1.1
  • v3.1.0
  • v3.0.16
  • v3.0.15
  • v3.0.14
  • v3.0.13
  • v3.0.12
  • v3.0.11
  • v3.0.10
  • v3.0.9
  • v3.0.8
  • v3.0.7
  • v3.0.6
  • v3.0.5
  • v3.0.4
25 results

utils.py

Blame
  • api.js 708 B
    import baseFetch from "unfetch";
    
    import { AuthStore } from "./stores";
    
    export const fetch = async (
      url,
      { headers = {}, expectedStatus = 200, method = "GET", body = null } = {}
    ) => {
      const { isAuthenticated, user } = AuthStore.getRawState();
    
      if (isAuthenticated) {
        headers.Authorization = "Bearer " + user.accessToken;
      }
    
      if (!headers["Content-Type"]) {
        headers["Content-Type"] = "application/json";
      }
    
      const response = await baseFetch(process.env.REACT_APP_API_BASE_URL + url, {
        body,
        method,
        headers,
      });
    
      if (!!expectedStatus && response.status !== expectedStatus) {
        throw new Error(`Unexpected status code ${response.status}`);
      }
    
      return response;
    };