Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds types to FetchService #45

Merged
merged 13 commits into from
Mar 22, 2023
16 changes: 11 additions & 5 deletions web/app/services/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// @ts-nocheck
// TODO: Type this file.
import Service from "@ember/service";
import fetch from "fetch";
import { inject as service } from "@ember/service";
import SessionService from "./session";

interface FetchOptions {
method?: string;
headers?: {
[key: string]: string;
};
body?: string;
}

export default class FetchService extends Service {
@service session;
@service declare session: SessionService;

async fetch(url, options = {}) {
async fetch(url: string, options: FetchOptions = {}) {
// Add the Google access token in a header (for auth) if the URL starts with
// a frontslash, which will only target the application backend.
if (Array.from(url)[0] == "/") {
Expand All @@ -18,7 +25,6 @@ export default class FetchService extends Service {
};
}
try {

const resp = await fetch(url, options);

if (!resp.ok) {
Expand Down