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

Function buildHandler

packages/base-driver/lib/protocol/route-handler.ts:87–188  ·  view source on GitHub ↗
(
  app: Application,
  method: string,
  path: string,
  spec: DriverMethodDef<Driver>,
  driver: Core<any>,
  isSessCmd: boolean,
)

Source from the content-addressed store, hash-verified

85}
86
87function buildHandler(
88 app: Application,
89 method: string,
90 path: string,
91 spec: DriverMethodDef<Driver>,
92 driver: Core<any>,
93 isSessCmd: boolean,
94): void {
95 const asyncHandler = async (req: Request, res: Response, abandonIfDisconnected?: () => boolean) => {
96 let httpResBody = {} as any;
97 let httpStatus = 200;
98 let newSessionId: string | undefined;
99 const sessionId = getSessionId(driver, req);
100
101 try {
102 logDeprecationWarning(driver, method, path, spec, sessionId);
103 ensureSessionExists(driver, sessionId, isSessCmd);
104 const jsonParseError = jsonParseErrors.getInvalidArgument(req);
105 if (jsonParseError) {
106 throw jsonParseError;
107 }
108 assertPostBodyIsJsonObject(req, spec);
109
110 const proxyOutcome = await tryWdProxy(driver, req, res, spec, isSessCmd, sessionId);
111 if (proxyOutcome === 'handled') {
112 return;
113 }
114 const didPluginOverrideProxy = proxyOutcome === 'plugin-override';
115
116 // if a command is not in our method map, it's because we
117 // have no plans to ever implement it
118 if (!spec.command) {
119 throw new errors.NotImplementedError();
120 }
121 const command = spec.command;
122
123 // Direct proxying delegates payload and command validation to the remote end.
124 // A plugin intercepting that same proxy path must preserve this ownership.
125 const jsonObj = preparePayload(spec, req.body, {
126 validatePayloadParams: !didPluginOverrideProxy,
127 });
128 const args = buildCommandArgs({
129 req,
130 jsonObj,
131 spec,
132 command,
133 validateCommandArguments: !didPluginOverrideProxy,
134 });
135
136 // run the driver command wrapped inside the argument validators
137 getLogger(driver, sessionId).debug(
138 `Calling %s.%s() with args: %s`,
139 driver.constructor.name,
140 command,
141 logger.markSensitive(util.truncateString(JSON.stringify(args), {length: MAX_LOG_BODY_LENGTH})),
142 );
143
144 const result = didPluginOverrideProxy

Callers 2

updateServerMethod · 0.85
registerCommandRoutesFunction · 0.85

Calls 1

handlerFunction · 0.50

Tested by

no test coverage detected