Skip to content

Commit 54bed49

Browse files
authored
unify and fix syntax of context.error and context.reject for cds service (#61)
* unify and fix syntax of context.error and context.reject for cds service * one more place to fix and a little polish
1 parent 37cab2a commit 54bed49

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/service/feature-service.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const redisReadHandler = async (context) => {
4545
"error during redis read"
4646
)
4747
);
48-
context.reject(500, { message: "caught unexpected error during redis read, check server logs" });
48+
context.reject({ code: 500, message: "caught unexpected error during redis read, check server logs" });
4949
}
5050
};
5151

@@ -75,7 +75,7 @@ const redisUpdateHandler = async (context) => {
7575
if (Array.isArray(validationErrors) && validationErrors.length > 0) {
7676
for (const { featureKey: target, errorMessage, errorMessageValues } of validationErrors) {
7777
const errorMessageWithValues = textFormat(errorMessage, errorMessageValues);
78-
context.error(VALIDATION_ERROR_HTTP_CODE, { message: errorMessageWithValues }, [], target);
78+
context.error({ code: VALIDATION_ERROR_HTTP_CODE, message: errorMessageWithValues, target });
7979
}
8080
}
8181
};
@@ -97,18 +97,19 @@ const redisUpdateHandler = async (context) => {
9797
"error during redis update"
9898
)
9999
);
100-
context.reject(500, { message: "caught unexpected error during redis update, check server logs" });
100+
context.reject({ code: 500, message: "caught unexpected error during redis update, check server logs" });
101101
}
102102
};
103103

104104
const redisSendCommandHandler = async (context) => {
105105
const { command } = context.data;
106106
if (!Array.isArray(command)) {
107-
context.reject(400, { message: "request body needs to contain a 'command' field of type array" });
107+
context.reject({ code: 400, message: "request body needs to contain a 'command' field of type array" });
108108
return;
109109
}
110-
const result = await redis.sendCommand(command);
111-
context.reply(typeof result === "string" ? result : JSON.stringify(result));
110+
const redisResponse = await redis.sendCommand(command);
111+
const result = typeof redisResponse === "string" ? redisResponse : JSON.stringify(redisResponse);
112+
context.reply(result);
112113
};
113114

114115
module.exports = async (srv) => {

0 commit comments

Comments
 (0)