Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions src/services/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { IErrorResponse } from '../models/error-response';
import { AlertService } from './alert.service';
import { PostFileMapManager } from './post-file-map';
import { ZzkSearchResult } from '../models/zzk-search-result';
import { got, gotWithBuffer } from '@/utils/http-client';
import got from '@/utils/http-client';
import httpClient from '@/utils/http-client';
import iconv from 'iconv-lite';

const defaultPageSize = 30;
Expand Down Expand Up @@ -69,7 +70,10 @@ export class PostService {
}

async fetchPostEditDto(postId: number, muteErrorNotification = false): Promise<PostEditDto | undefined> {
const response = await gotWithBuffer(`${this._baseUrl}/api/posts/${postId}`);
const response = await httpClient.get(`${this._baseUrl}/api/posts/${postId}`, {
throwHttpErrors: false,
responseType: 'buffer',
});

try {
throwIfNotOkGotResponse(response);
Expand Down
11 changes: 1 addition & 10 deletions src/utils/http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ const httpClient = got.extend({
https: { rejectUnauthorized: false },
});

const gotWithBuffer = got.extend({
hooks: {
beforeRequest: [bearerTokenHook],
},
throwHttpErrors: false,
https: { rejectUnauthorized: false },
responseType: 'buffer',
});

export { got, gotWithBuffer };
export { got };
export * from 'got';
export default httpClient;
5 changes: 3 additions & 2 deletions src/utils/throw-if-not-ok-response.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GotFetchResponse } from 'got-fetch/out/lib/response';
import { Response as GotResponse } from 'got';
import { IErrorResponse, isErrorResponse } from '../models/error-response';
import iconv from 'iconv-lite';

const throwIfNotOkResponse = async (response: GotFetchResponse) => {
if (!response.ok) {
Expand All @@ -21,9 +22,9 @@ const throwIfNotOkResponse = async (response: GotFetchResponse) => {
}
};

const throwIfNotOkGotResponse = (response: GotResponse<string>) => {
const throwIfNotOkGotResponse = (response: GotResponse<Buffer>) => {
if (!response.ok) {
const responseText = response.body;
const responseText = iconv.decode(response.rawBody, 'utf-8');
let responseJson: unknown;
try {
responseJson = JSON.parse(responseText);
Expand Down