Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-mice-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/service-utils": patch
---

Better error messages for 403 responses
8 changes: 4 additions & 4 deletions packages/service-utils/src/core/authorize/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ describe("authorizeService", () => {
// biome-ignore lint/suspicious/noExplicitAny: test only
) as any;
expect(result.authorized).toBe(false);
expect(result.errorMessage).toBe(
"Invalid request: Unauthorized service: nebula. You can view the restrictions for this team in your dashboard: https://thirdweb.com",
expect(result.errorMessage).toContain(
"Invalid request: Unauthorized service: nebula",
);
expect(result.errorCode).toBe("SERVICE_UNAUTHORIZED");
expect(result.status).toBe(403);
Expand All @@ -52,8 +52,8 @@ describe("authorizeService", () => {
// biome-ignore lint/suspicious/noExplicitAny: test only
) as any;
expect(result.authorized).toBe(false);
expect(result.errorMessage).toBe(
"Invalid request: Unauthorized action: storage unauthorized-action. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key",
expect(result.errorMessage).toContain(
"Invalid request: Unauthorized action: storage unauthorized-action",
);
expect(result.errorCode).toBe("SERVICE_ACTION_UNAUTHORIZED");
expect(result.status).toBe(403);
Expand Down
6 changes: 3 additions & 3 deletions packages/service-utils/src/core/authorize/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function authorizeService(
if (!team.enabledScopes.includes(serviceConfig.serviceScope)) {
return {
authorized: false,
errorMessage: `Invalid request: Unauthorized service: ${serviceConfig.serviceScope}. You can view the restrictions for this team in your dashboard: https://thirdweb.com`,
errorMessage: `Invalid request: Unauthorized service: ${serviceConfig.serviceScope} for team: ${team.name} (${team.id}). You can view the restrictions for this team in your dashboard: https://thirdweb.com`,
errorCode: "SERVICE_UNAUTHORIZED",
status: 403,
};
Expand All @@ -42,7 +42,7 @@ export function authorizeService(
if (!service) {
return {
authorized: false,
errorMessage: `Invalid request: Unauthorized service: ${serviceConfig.serviceScope}. You can view the restrictions on this project in your dashboard: https://thirdweb.com`,
errorMessage: `Invalid request: Unauthorized service: ${serviceConfig.serviceScope} for project: ${project.name} (${project.publishableKey}). You can view the restrictions on this project in your dashboard: https://thirdweb.com`,
errorCode: "SERVICE_UNAUTHORIZED",
status: 403,
};
Expand All @@ -56,7 +56,7 @@ export function authorizeService(
if (!isActionAllowed) {
return {
authorized: false,
errorMessage: `Invalid request: Unauthorized action: ${serviceConfig.serviceScope} ${serviceConfig.serviceAction}. You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
errorMessage: `Invalid request: Unauthorized action: ${serviceConfig.serviceScope} ${serviceConfig.serviceAction} for project: ${project.name} (${project.publishableKey}). You can view the restrictions on this API key in your dashboard: https://thirdweb.com/create-api-key`,
errorCode: "SERVICE_ACTION_UNAUTHORIZED",
status: 403,
};
Expand Down
Loading