fix: 修复simpleConnector中,message传递未使用encodeURIComponent导致koa报错的bug

This commit is contained in:
Pan Qiancheng 2025-12-18 16:35:15 +08:00
parent 8adf31af12
commit caad35beea
3 changed files with 15 additions and 9 deletions

View File

@ -33,19 +33,19 @@ export default class SimpleConnector<ED extends EntityDict & BaseEntityDict, Fro
protected parseAspectResult(response: Response): Promise<{
result: any;
opRecords: any;
message: string | null;
message: string | undefined;
} | {
result: ReadableStream<Uint8Array<ArrayBuffer>> | null;
message: string | null;
message: string | undefined;
opRecords?: undefined;
}>;
callAspect(name: string, params: any, context?: FrontCxt): Promise<{
result: any;
opRecords: any;
message: string | null;
message: string | undefined;
} | {
result: ReadableStream<Uint8Array<ArrayBuffer>> | null;
message: string | null;
message: string | undefined;
opRecords?: undefined;
}>;
getRouter(): string;
@ -62,7 +62,7 @@ export default class SimpleConnector<ED extends EntityDict & BaseEntityDict, Fro
aspectName: string;
data: any;
};
serializeResult(result: any, opRecords: OpRecord<ED>[], headers: IncomingHttpHeaders, body: any, message?: string): Promise<{
serializeResult(result: any, opRecords: OpRecord<ED>[], headers: IncomingHttpHeaders, body: any, rawMessage?: string): Promise<{
body: any;
headers?: Record<string, any> | undefined;
}>;

View File

@ -80,7 +80,8 @@ class SimpleConnector {
if (response.status > 299) {
throw new types_1.OakServerProxyException(`网络请求返回status是${response.status}`);
}
const message = response.headers.get('oak-message');
const rawMessage = response.headers.get('oak-message');
const message = rawMessage ? decodeURIComponent(rawMessage) : undefined;
const responseType = response.headers.get('Content-Type') || response.headers.get('content-type');
if (responseType?.toLocaleLowerCase().match(/application\/json/i)) {
const { exception, result, opRecords } = await response.json();
@ -188,7 +189,8 @@ class SimpleConnector {
data: files ? Object.assign({}, body, files) : body,
};
}
async serializeResult(result, opRecords, headers, body, message) {
async serializeResult(result, opRecords, headers, body, rawMessage) {
const message = rawMessage ? encodeURIComponent(rawMessage) : undefined;
if (result instanceof stream_1.Stream || result instanceof Buffer) {
return {
body: result,

View File

@ -93,7 +93,8 @@ export default class SimpleConnector<ED extends EntityDict & BaseEntityDict, Fro
);
}
const message = response.headers.get('oak-message');
const rawMessage = response.headers.get('oak-message');
const message = rawMessage ? decodeURIComponent(rawMessage) : undefined;
const responseType = response.headers.get('Content-Type') || response.headers.get('content-type');
if (responseType?.toLocaleLowerCase().match(/application\/json/i)) {
const { exception, result, opRecords } = await response.json();
@ -219,8 +220,11 @@ export default class SimpleConnector<ED extends EntityDict & BaseEntityDict, Fro
opRecords: OpRecord<ED>[],
headers: IncomingHttpHeaders,
body: any,
message?: string
rawMessage?: string
): Promise<{ body: any; headers?: Record<string, any> | undefined }> {
const message = rawMessage ? encodeURIComponent(rawMessage) : undefined;
if (result instanceof Stream || result instanceof Buffer) {
return {
body: result,