Skip to content

Commit bf5323f

Browse files
abnegateclaude
andcommitted
(refactor): remove dead try-catch rethrow in Adapter::route
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7c23b5c commit bf5323f

1 file changed

Lines changed: 39 additions & 43 deletions

File tree

src/Adapter.php

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -101,58 +101,54 @@ public function route(string $data): ConnectionResult
101101
}
102102
}
103103

104-
try {
105-
if ($this->callback !== null) {
106-
$resolved = ($this->callback)($data);
107-
if ($resolved instanceof Resolver\Result) {
108-
$result = $resolved;
109-
} elseif (\is_string($resolved)) {
110-
$result = new Resolver\Result(endpoint: $resolved);
111-
} else {
112-
throw new ResolverException(
113-
'Resolve callback must return Result or string',
114-
ResolverException::INTERNAL
115-
);
116-
}
117-
} elseif ($this->resolver !== null) {
118-
$result = $this->resolver->resolve($data);
104+
if ($this->callback !== null) {
105+
$resolved = ($this->callback)($data);
106+
if ($resolved instanceof Resolver\Result) {
107+
$result = $resolved;
108+
} elseif (\is_string($resolved)) {
109+
$result = new Resolver\Result(endpoint: $resolved);
119110
} else {
120111
throw new ResolverException(
121-
'No resolver or resolve callback configured',
122-
ResolverException::NOT_FOUND
112+
'Resolve callback must return Result or string',
113+
ResolverException::INTERNAL
123114
);
124115
}
125-
$endpoint = $result->endpoint;
116+
} elseif ($this->resolver !== null) {
117+
$result = $this->resolver->resolve($data);
118+
} else {
119+
throw new ResolverException(
120+
'No resolver or resolve callback configured',
121+
ResolverException::NOT_FOUND
122+
);
123+
}
124+
$endpoint = $result->endpoint;
126125

127-
if ($endpoint === '') {
128-
throw new ResolverException(
129-
"Resolver returned empty endpoint for: {$data}",
130-
ResolverException::NOT_FOUND
131-
);
132-
}
126+
if ($endpoint === '') {
127+
throw new ResolverException(
128+
"Resolver returned empty endpoint for: {$data}",
129+
ResolverException::NOT_FOUND
130+
);
131+
}
133132

134-
if (!$this->skipValidation) {
135-
$endpoint = $this->validate($endpoint);
136-
}
133+
if (! $this->skipValidation) {
134+
$endpoint = $this->validate($endpoint);
135+
}
137136

138-
if ($this->cacheTTL > 0) {
139-
$this->router->set($data, [
140-
'endpoint' => $endpoint,
141-
'updated' => $now,
142-
]);
143-
}
137+
if ($this->cacheTTL > 0) {
138+
$this->router->set($data, [
139+
'endpoint' => $endpoint,
140+
'updated' => $now,
141+
]);
142+
}
144143

145-
$metadata = $result->metadata;
146-
$metadata['cached'] = false;
144+
$metadata = $result->metadata;
145+
$metadata['cached'] = false;
147146

148-
return new ConnectionResult(
149-
endpoint: $endpoint,
150-
protocol: $this->getProtocol(),
151-
metadata: $metadata,
152-
);
153-
} catch (\Exception $e) {
154-
throw $e;
155-
}
147+
return new ConnectionResult(
148+
endpoint: $endpoint,
149+
protocol: $this->getProtocol(),
150+
metadata: $metadata,
151+
);
156152
}
157153

158154
/**

0 commit comments

Comments
 (0)