Skip to content

Commit

Permalink
Add Fetch API
Browse files Browse the repository at this point in the history
ingalls committed Oct 20, 2023

Verified

This commit was signed with the committer’s verified signature.
ingalls Nick
1 parent c05caf5 commit 3578778
Showing 3 changed files with 182 additions and 114 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,10 @@

## Version History

### v2.1.0

- :tada: Add generic fetch method

### v2.0.2

- :bug: Fix existance check not being thrown
19 changes: 19 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -118,6 +118,25 @@ export default class TaskBase {
}
}

async fetch(url: string, method: string, body: object): object {
console.log(`ok - ${method}: ${url}`);
const res = await fetch(new URL(url, this.etl.api), {
method,
headers: {
'Authorization': `Bearer ${this.etl.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
});

if (!res.ok) {
console.error(await res.text());
throw new Error('Failed to make request to API');
} else {
return await res.json();
}
}

/**
* Post an Alert to the Layer Alert API
*
273 changes: 159 additions & 114 deletions package-lock.json

0 comments on commit 3578778

Please sign in to comment.