-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[playground-preview-worker] fix: don't report invalid upload input #4937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f7aa408
fix: don't report invalid `playground-preview-worker` upload input
mrbbot 1e29ffa
fix: bump `hono` to address cooking parsing issues
mrbbot bcfb5ff
chore: add standard linting rules to `playground-preview-worker`
mrbbot f169ac7
fix: remove playground worker circular dependency on `index.ts`
mrbbot d07ec1b
fix: include form data parsing errors in user facing message
mrbbot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| module.exports = { | ||
| root: true, | ||
| extends: ["@cloudflare/eslint-config-worker"], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import type { ZodIssue } from "zod"; | ||
|
|
||
| export class HttpError extends Error { | ||
| constructor( | ||
| message: string, | ||
| readonly status: number, | ||
| // Only report errors to sentry when they represent actionable errors | ||
| readonly reportable: boolean | ||
| ) { | ||
| super(message); | ||
| Object.setPrototypeOf(this, new.target.prototype); | ||
| } | ||
| toResponse() { | ||
| return Response.json( | ||
| { | ||
| error: this.name, | ||
| message: this.message, | ||
| data: this.data, | ||
| }, | ||
| { | ||
| status: this.status, | ||
| headers: { | ||
| "Access-Control-Allow-Origin": "*", | ||
| "Access-Control-Allow-Methods": "GET,PUT,POST", | ||
| }, | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| get data(): Record<string, unknown> { | ||
| return {}; | ||
| } | ||
| } | ||
|
|
||
| export class WorkerTimeout extends HttpError { | ||
| name = "WorkerTimeout"; | ||
| constructor() { | ||
| super("Worker timed out", 400, false); | ||
| } | ||
|
|
||
| toResponse(): Response { | ||
| return new Response("Worker timed out"); | ||
| } | ||
| } | ||
|
|
||
| export class ServiceWorkerNotSupported extends HttpError { | ||
| name = "ServiceWorkerNotSupported"; | ||
| constructor() { | ||
| super( | ||
| "Service Workers are not supported in the Workers Playground", | ||
| 400, | ||
| false | ||
| ); | ||
| } | ||
| } | ||
| export class ZodSchemaError extends HttpError { | ||
| name = "ZodSchemaError"; | ||
| constructor(private issues: ZodIssue[]) { | ||
| super("Something went wrong", 500, true); | ||
| } | ||
|
|
||
| get data(): { issues: string } { | ||
| return { issues: JSON.stringify(this.issues) }; | ||
| } | ||
| } | ||
|
|
||
| export class PreviewError extends HttpError { | ||
| name = "PreviewError"; | ||
| constructor(private error: string) { | ||
| super(error, 400, false); | ||
| } | ||
|
|
||
| get data(): { error: string } { | ||
| return { error: this.error }; | ||
| } | ||
| } | ||
|
|
||
| export class TokenUpdateFailed extends HttpError { | ||
| name = "TokenUpdateFailed"; | ||
| constructor() { | ||
| super("Provide valid token", 400, false); | ||
| } | ||
| } | ||
|
|
||
| export class RawHttpFailed extends HttpError { | ||
| name = "RawHttpFailed"; | ||
| constructor() { | ||
| super("Provide valid token", 400, false); | ||
| } | ||
| } | ||
|
|
||
| export class PreviewRequestFailed extends HttpError { | ||
| name = "PreviewRequestFailed"; | ||
| constructor(private tokenId: string | undefined, reportable: boolean) { | ||
| super("Valid token not found", 400, reportable); | ||
| } | ||
| get data(): { tokenId: string | undefined } { | ||
| return { tokenId: this.tokenId }; | ||
| } | ||
| } | ||
|
|
||
| export class UploadFailed extends HttpError { | ||
| name = "UploadFailed"; | ||
| constructor() { | ||
| super("Valid token not provided", 401, false); | ||
| } | ||
| } | ||
|
|
||
| export class PreviewRequestForbidden extends HttpError { | ||
| name = "PreviewRequestForbidden"; | ||
| constructor() { | ||
| super("Preview request forbidden", 403, false); | ||
| } | ||
| } | ||
|
|
||
| export class BadUpload extends HttpError { | ||
| name = "BadUpload"; | ||
| constructor(message = "Invalid upload", private readonly error?: string) { | ||
| super(message, 400, false); | ||
| } | ||
| get data() { | ||
| return { error: this.error }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.