File tree Expand file tree Collapse file tree 3 files changed +10
-14
lines changed Expand file tree Collapse file tree 3 files changed +10
-14
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ import { IErrorResponse } from '../models/error-response';
1010import { AlertService } from './alert.service' ;
1111import { PostFileMapManager } from './post-file-map' ;
1212import { ZzkSearchResult } from '../models/zzk-search-result' ;
13- import { got , gotWithBuffer } from '@/utils/http-client' ;
13+ import got from '@/utils/http-client' ;
14+ import httpClient from '@/utils/http-client' ;
1415import iconv from 'iconv-lite' ;
1516
1617const defaultPageSize = 30 ;
@@ -69,7 +70,10 @@ export class PostService {
6970 }
7071
7172 async fetchPostEditDto ( postId : number , muteErrorNotification = false ) : Promise < PostEditDto | undefined > {
72- const response = await gotWithBuffer ( `${ this . _baseUrl } /api/posts/${ postId } ` ) ;
73+ const response = await httpClient . get ( `${ this . _baseUrl } /api/posts/${ postId } ` , {
74+ throwHttpErrors : false ,
75+ responseType : 'buffer' ,
76+ } ) ;
7377
7478 try {
7579 throwIfNotOkGotResponse ( response ) ;
Original file line number Diff line number Diff line change @@ -20,15 +20,6 @@ const httpClient = got.extend({
2020 https : { rejectUnauthorized : false } ,
2121} ) ;
2222
23- const gotWithBuffer = got . extend ( {
24- hooks : {
25- beforeRequest : [ bearerTokenHook ] ,
26- } ,
27- throwHttpErrors : false ,
28- https : { rejectUnauthorized : false } ,
29- responseType : 'buffer' ,
30- } ) ;
31-
32- export { got , gotWithBuffer } ;
23+ export { got } ;
3324export * from 'got' ;
3425export default httpClient ;
Original file line number Diff line number Diff line change 11import { GotFetchResponse } from 'got-fetch/out/lib/response' ;
22import { Response as GotResponse } from 'got' ;
33import { IErrorResponse , isErrorResponse } from '../models/error-response' ;
4+ import iconv from 'iconv-lite' ;
45
56const throwIfNotOkResponse = async ( response : GotFetchResponse ) => {
67 if ( ! response . ok ) {
@@ -21,9 +22,9 @@ const throwIfNotOkResponse = async (response: GotFetchResponse) => {
2122 }
2223} ;
2324
24- const throwIfNotOkGotResponse = ( response : GotResponse < string > ) => {
25+ const throwIfNotOkGotResponse = ( response : GotResponse < Buffer > ) => {
2526 if ( ! response . ok ) {
26- const responseText = response . body ;
27+ const responseText = iconv . decode ( response . rawBody , 'utf-8' ) ;
2728 let responseJson : unknown ;
2829 try {
2930 responseJson = JSON . parse ( responseText ) ;
You can’t perform that action at this time.
0 commit comments