Skip to content

Commit

Permalink
fix: ctx.body赋值
Browse files Browse the repository at this point in the history
  • Loading branch information
linyyyang committed Nov 1, 2022
1 parent 1cf7b97 commit 694e8c5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
10 changes: 4 additions & 6 deletions src/handler/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Usage:
* @Author: richen
* @Date: 2021-11-19 00:23:06
* @LastEditTime: 2022-03-02 18:49:41
* @LastEditTime: 2022-11-01 15:42:27
*/
import * as Helper from "koatty_lib";
import { KoattyContext } from "koatty_core";
Expand Down Expand Up @@ -45,14 +45,12 @@ export async function grpcHandler(ctx: KoattyContext, next: Function, ext?: any)
try {
response.timeout = null;
// promise.race
const res = await Promise.race([new Promise((resolve, reject) => {
await Promise.race([new Promise((resolve, reject) => {
response.timeout = setTimeout(reject, timeout, new Exception('Deadline exceeded', 1, 4));
return;
}), next()]);
if (!Helper.isTrueEmpty(res)) {
ctx.body = res;
}
if (ctx.body && ctx.status === 404) {

if (ctx.body !== undefined && ctx.status === 404) {
ctx.status = 200;
}
if (ctx.status >= 400) {
Expand Down
10 changes: 6 additions & 4 deletions src/handler/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Usage:
* @Author: richen
* @Date: 2021-11-19 00:14:59
* @LastEditTime: 2022-03-02 18:49:33
* @LastEditTime: 2022-11-01 15:42:41
*/
import { Helper } from "koatty_lib";
import { catcher } from "../catcher";
Expand Down Expand Up @@ -45,13 +45,15 @@ export async function httpHandler(ctx: KoattyContext, next: Function, ext?: any)
try {
response.timeout = null;
// promise.race
const res = await Promise.race([new Promise((resolve, reject) => {
await Promise.race([new Promise((resolve, reject) => {
response.timeout = setTimeout(reject, timeout, new Exception('Request Timeout', 1, 408));
return;
}), next()]);
if (!Helper.isTrueEmpty(res)) {
ctx.body = res;

if (ctx.body !== undefined && ctx.status === 404) {
ctx.status = 200;
}

if (ctx.status >= 400) {
throw new Exception('', 1, ctx.status);
}
Expand Down
9 changes: 3 additions & 6 deletions src/handler/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Usage:
* @Author: richen
* @Date: 2021-11-19 00:24:43
* @LastEditTime: 2022-03-02 18:49:17
* @LastEditTime: 2022-11-01 15:42:24
*/
import { inspect } from "util";
import * as Helper from "koatty_lib";
Expand Down Expand Up @@ -56,15 +56,12 @@ export async function wsHandler(ctx: KoattyContext, next: Function, ext?: any):
try {
response.timeout = null;
// promise.race
const res = await Promise.race([new Promise((resolve, reject) => {
await Promise.race([new Promise((resolve, reject) => {
response.timeout = setTimeout(reject, timeout, new Exception('Request Timeout', 1, 408));
return;
}), next()]);

if (!Helper.isTrueEmpty(res)) {
ctx.body = res;
}
if (ctx.body && ctx.status === 404) {
if (ctx.body !== undefined && ctx.status === 404) {
ctx.status = 200;
}
if (ctx.status >= 400) {
Expand Down

0 comments on commit 694e8c5

Please sign in to comment.