diff --git a/src/services/post.service.ts b/src/services/post.service.ts index c21c43f7..f9618568 100644 --- a/src/services/post.service.ts +++ b/src/services/post.service.ts @@ -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; @@ -69,7 +70,10 @@ export class PostService { } async fetchPostEditDto(postId: number, muteErrorNotification = false): Promise { - 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); diff --git a/src/utils/http-client.ts b/src/utils/http-client.ts index 810e3755..de2bfbec 100644 --- a/src/utils/http-client.ts +++ b/src/utils/http-client.ts @@ -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; diff --git a/src/utils/throw-if-not-ok-response.ts b/src/utils/throw-if-not-ok-response.ts index a7fa6ed8..b6a75529 100644 --- a/src/utils/throw-if-not-ok-response.ts +++ b/src/utils/throw-if-not-ok-response.ts @@ -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) { @@ -21,9 +22,9 @@ const throwIfNotOkResponse = async (response: GotFetchResponse) => { } }; -const throwIfNotOkGotResponse = (response: GotResponse) => { +const throwIfNotOkGotResponse = (response: GotResponse) => { if (!response.ok) { - const responseText = response.body; + const responseText = iconv.decode(response.rawBody, 'utf-8'); let responseJson: unknown; try { responseJson = JSON.parse(responseText);