MCPcopy Create free account
hub / github.com/appium/appium / buildHandler

Method buildHandler

packages/storage-plugin/lib/plugin.ts:36–63  ·  view source on GitHub ↗
(methodName: string, prefix: string, endpoint: string, isDeprecated: boolean)

Source from the content-addressed store, hash-verified

34 const serverBasePath = httpServer.basePath;
35 const buildHandler =
36 (methodName: string, prefix: string, endpoint: string, isDeprecated: boolean) =>
37 async (req: Request, res: Response) => {
38 // the server base path is intentionally omitted from the log message
39 const routePath = `${prefix}${endpoint}`;
40 if (isDeprecated && !deprecatedRoutesLogged.has(routePath)) {
41 deprecatedRoutesLogged.add(routePath);
42 log.warn(
43 `The '${routePath}' endpoint has been deprecated and will be removed in a future version ` +
44 `of the storage plugin. Please use '${STORAGE_PREFIX}${endpoint}' instead`,
45 );
46 }
47
48 let status = 200;
49 let body: any;
50 try {
51 const value = await STORAGE_HANDLERS[methodName](req, httpServer, `${serverBasePath}${prefix}`);
52 body = {value: value ?? null};
53 } catch (e) {
54 [status, body] = getResponseForW3CError(e);
55 }
56 log.debug(
57 'Responding to %s with %s',
58 methodName,
59 logger.markSensitive(util.truncateString(JSON.stringify(body.value), {length: 200})),
60 );
61 res.set('content-type', 'application/json; charset=utf-8');
62 res.status(status).send(body);
63 };
64
65 for (const [prefix, isDeprecated] of [
66 [STORAGE_PREFIX, false],

Callers

nothing calls this directly

Calls 6

getResponseForW3CErrorFunction · 0.85
setMethod · 0.80
warnMethod · 0.65
debugMethod · 0.65
addMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected