Skip to content

Commit d7a3b7d

Browse files
authored
Log proxy errors (#519)
## Description <!-- Provide a brief description of the changes in this PR --> Add logging to proxy endpoint to see where error occurs when fetching ipfs urls on vercel backend ## Type of change <!-- Check the appropriate options that apply to this PR --> - [ ] Bug fix - [ ] New feature - [ ] Protocol integration - [ ] Documentation update - [x] Other (please describe): logging for bug fix <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Add logging to proxy endpoint in `route.ts` to diagnose errors when fetching IPFS URLs, and fix indentation in `ip.ts`. > > - **Logging**: > - Add `console.error` for unsupported protocol and private IP detection in `GET()` in `route.ts`. > - Log general errors in `GET()` in `route.ts`. > - **Formatting**: > - Fix indentation in `checkURLForPrivateIP()` in `ip.ts`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=solana-foundation%2Fexplorer&utm_source=github&utm_medium=referral)<sup> for d54cb45. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent bad411a commit d7a3b7d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

app/api/metadata/proxy/feature/ip.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export async function checkURLForPrivateIP(uri: URL | string) {
9090
for (const address of addresses) {
9191
if (isPrivateIP(address.address)) {
9292
return true;
93-
}
93+
}
9494
}
9595
} else {
9696
const singleResult = addresses as unknown as LookupAddressResult;

app/api/metadata/proxy/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const TIMEOUT = process.env.NEXT_PUBLIC_METADATA_TIMEOUT
1818
/**
1919
* Respond with error in a JSON format
2020
*/
21-
function respondWithError(status: keyof typeof errors, message?: string){
21+
function respondWithError(status: keyof typeof errors, message?: string) {
2222
return NextResponse.json({ error: message ?? errors[status].message }, { status });
2323
}
2424

@@ -47,14 +47,17 @@ export async function GET(
4747

4848
// check that uri has supported protocol despite of any other checks
4949
if (!isHTTPProtocol(parsedUrl)) {
50+
console.error('Unsupported protocol', parsedUrl.protocol);
5051
return respondWithError(400);
5152
}
5253

5354
const isPrivate = await checkURLForPrivateIP(parsedUrl);
5455
if (isPrivate) {
56+
console.error('Private IP detected', parsedUrl.hostname);
5557
return respondWithError(403);
5658
}
5759
} catch (_error) {
60+
console.error(_error);
5861
return respondWithError(400);
5962
}
6063

0 commit comments

Comments
 (0)