Compare commits
No commits in common. "dabaaf3ced25143025a1115432cc372ddd9d1e6b" and "dfe79e2fc2e9756e54bfbdec97333d768af333a7" have entirely different histories.
dabaaf3ced
...
dfe79e2fc2
52
src/axios.ts
52
src/axios.ts
|
@ -1,37 +1,31 @@
|
||||||
import Axios, {AxiosError, AxiosRequestConfig} from "axios";
|
import Axios, { AxiosRequestConfig } from "axios";
|
||||||
import {S5Error} from "#client.js";
|
|
||||||
|
|
||||||
export const customInstance = <T>(
|
export const customInstance = <T>(
|
||||||
config: AxiosRequestConfig,
|
config: AxiosRequestConfig,
|
||||||
options?: AxiosRequestConfig,
|
options?: AxiosRequestConfig,
|
||||||
): Promise<T> => {
|
): Promise<T> => {
|
||||||
const source = Axios.CancelToken.source();
|
const source = Axios.CancelToken.source();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Hack to ensure that the data is passed to the request as an option.
|
Hack to ensure that the data is passed to the request as an option.
|
||||||
*/
|
*/
|
||||||
if (options?.data) {
|
if (options?.data) {
|
||||||
config = config || {};
|
config = config || {};
|
||||||
config.data = options.data;
|
config.data = options.data;
|
||||||
delete config.data;
|
delete config.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const instance = Axios.create({baseURL: options?.baseURL});
|
const instance = Axios.create({ baseURL: options?.baseURL });
|
||||||
const promise = instance({
|
const promise = instance({
|
||||||
...config,
|
...config,
|
||||||
...options,
|
...options,
|
||||||
cancelToken: source.token,
|
cancelToken: source.token,
|
||||||
}).then(({data}) => data).catch((error) => {
|
}).then(({ data }) => data);
|
||||||
if (Axios.isCancel(error)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new S5Error((error as AxiosError).message, (error as AxiosError).response?.status as number);
|
|
||||||
})
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
promise.cancel = () => {
|
promise.cancel = () => {
|
||||||
source.cancel("Query was cancelled");
|
source.cancel("Query was cancelled");
|
||||||
};
|
};
|
||||||
|
|
||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,16 +70,6 @@ import { Multihash } from "@lumeweb/libs5/lib/multihash.js";
|
||||||
import { blake3 } from "@noble/hashes/blake3";
|
import { blake3 } from "@noble/hashes/blake3";
|
||||||
import { base64urlDecode, base64urlEncode } from "#utils/encoding.js";
|
import { base64urlDecode, base64urlEncode } from "#utils/encoding.js";
|
||||||
|
|
||||||
export class S5Error extends Error {
|
|
||||||
public statusCode: number;
|
|
||||||
|
|
||||||
constructor(message: string, statusCode: number) {
|
|
||||||
super(message);
|
|
||||||
this.name = "S5Error";
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The S5 Client which can be used to access S5-net.
|
* The S5 Client which can be used to access S5-net.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -900,8 +900,6 @@ components:
|
||||||
$ref: "#/components/schemas/AccountStats"
|
$ref: "#/components/schemas/AccountStats"
|
||||||
AccountPinsResponse:
|
AccountPinsResponse:
|
||||||
type: object
|
type: object
|
||||||
required:
|
|
||||||
- pins
|
|
||||||
properties:
|
properties:
|
||||||
pins:
|
pins:
|
||||||
type: array
|
type: array
|
||||||
|
|
Loading…
Reference in New Issue