mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 21:16:09 +00:00
fix(rest): response error
This commit is contained in:
parent
220069a89c
commit
bd7b8bca52
@ -449,10 +449,9 @@ export class Message implements Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** deletes this message */
|
/** deletes this message */
|
||||||
async delete(reason?: string): Promise<Message> {
|
async delete(): Promise<Message> {
|
||||||
await this.session.rest.delete<void>(
|
await this.session.rest.delete<void>(
|
||||||
CHANNEL_MESSAGE(this.channelId, this.id),
|
CHANNEL_MESSAGE(this.channelId, this.id)
|
||||||
{ headers: { 'X-Audit-Log-Reason': reason } }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -266,7 +266,6 @@ export class DefaultRestAdapter implements RestAdapter {
|
|||||||
}
|
}
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const url = route[0] === '/' ? `${this.url}${route}` : route;
|
const url = route[0] === '/' ? `${this.url}${route}` : route;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.processRequest(
|
this.processRequest(
|
||||||
{
|
{
|
||||||
@ -279,7 +278,7 @@ export class DefaultRestAdapter implements RestAdapter {
|
|||||||
);
|
);
|
||||||
reject(restError);
|
reject(restError);
|
||||||
},
|
},
|
||||||
resolve: (data: any) => resolve(JSON.parse(data.body)),
|
resolve: (data: any) => resolve(data.body ? JSON.parse(data.body) : {}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
bucketId: options?.bucketId,
|
bucketId: options?.bucketId,
|
||||||
@ -304,7 +303,6 @@ export class DefaultRestAdapter implements RestAdapter {
|
|||||||
body: options.payload?.body,
|
body: options.payload?.body,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const bucketIdFromHeaders = this.processRequestHeaders(
|
const bucketIdFromHeaders = this.processRequestHeaders(
|
||||||
options.url,
|
options.url,
|
||||||
response.headers
|
response.headers
|
||||||
@ -314,6 +312,15 @@ export class DefaultRestAdapter implements RestAdapter {
|
|||||||
options.bucketId = bucketIdFromHeaders;
|
options.bucketId = bucketIdFromHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response.status === 204) {
|
||||||
|
options.resolve?.({
|
||||||
|
ok: true,
|
||||||
|
status: 204,
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (response.status < 200 || response.status >= 400) {
|
if (response.status < 200 || response.status >= 400) {
|
||||||
let error = 'REQUEST_UNKNOWN_ERROR';
|
let error = 'REQUEST_UNKNOWN_ERROR';
|
||||||
|
|
||||||
@ -401,15 +408,6 @@ export class DefaultRestAdapter implements RestAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.status === 204) {
|
|
||||||
options.resolve?.({
|
|
||||||
ok: true,
|
|
||||||
status: 204,
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const json = JSON.stringify(await response.json());
|
const json = JSON.stringify(await response.json());
|
||||||
|
|
||||||
options.resolve?.({
|
options.resolve?.({
|
||||||
|
@ -115,7 +115,7 @@ export interface RestAdapter {
|
|||||||
|
|
||||||
delete<T>(
|
delete<T>(
|
||||||
router: string,
|
router: string,
|
||||||
data: unknown,
|
data?: unknown,
|
||||||
options?: {
|
options?: {
|
||||||
retryCount?: number;
|
retryCount?: number;
|
||||||
bucketId?: string;
|
bucketId?: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user