Skip to content

Commit

Permalink
add a few comments
Browse files Browse the repository at this point in the history
  • Loading branch information
koresar committed May 18, 2024
1 parent a492975 commit d8cb868
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/server/Allserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ module.exports = require("stampit")({
await this.transport.prepareIntrospectionReply(ctx);
},

/**
* This method does not throw.
* The `ctx.procedure` is the function to call.
* @param ctx
* @return {Promise<void>}
* @private
*/
async _callProcedure(ctx) {
if (!isFunction(ctx.procedure)) {
ctx.result = {
Expand Down Expand Up @@ -99,24 +106,21 @@ module.exports = require("stampit")({
return;
}
const middleware = middlewares[0];
async function handleMiddlewareResult(result) {
if (result !== undefined) {
ctx.result = result;
// Do not call any more middlewares
} else {
await runMiddlewares(middlewares.slice(1));
}
}
try {
if (middleware.length > 1) {
await middleware.call(this, ctx, async (result) => {
if (result !== undefined) {
ctx.result = result;
// Do not call any more middlewares
} else {
await runMiddlewares(middlewares.slice(1));
}
});
// This middleware accepts more than one argument
await middleware.call(this, ctx, handleMiddlewareResult);
} else {
const result = await middleware.call(this, ctx);
if (result !== undefined) {
ctx.result = result;
// Do not call any more middlewares
} else {
await runMiddlewares(middlewares.slice(1));
}
await handleMiddlewareResult(result);
}
} catch (err) {
const code = err.code || "ALLSERVER_MIDDLEWARE_ERROR";
Expand Down

0 comments on commit d8cb868

Please sign in to comment.