Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ export class API {
let j = await response.json()
// console.log("j:", j)
if (j.error && j.error.message) {
throw new APIError(j.error.message, { status: response.status, data: j, cause: j.error })
throw new APIError(j.error.message, { status: response.status, data: j, cause: j.error, headers: response.headers })
} else {
throw new APIError(JSON.stringify(j), { status: response.status, data: j })
throw new APIError(JSON.stringify(j), { status: response.status, data: j, headers: response.headers })
}
} else {
throw new APIError(await response.text(), { status: response.status })
Expand Down Expand Up @@ -143,9 +143,9 @@ export function apiInit(options = {}) {
}

export function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
const value = `; ${document.cookie}`
const parts = value.split(`; ${name}=`)
if (parts.length === 2) return parts.pop().split(';').shift()
}

class APIError extends Error {
Expand All @@ -168,6 +168,9 @@ class APIError extends Error {
get data() {
return this.options.data
}
get headers() {
return this.options.headers
}

toString() {
return super.toString()
Expand Down