fix: Scratch URL loader migrates to CDK proxy and shows specific error messages#574
Merged
Merged
Conversation
旧 SAM 実装 (smalruby/smalruby-infra) の 4 エンドポイントを CDK プロジェクト infra/smalruby-api/ に移行し、HTTP API v2 + TypeScript Lambda で再実装した。 - REST API v1 → HTTP API v2 (built-in CORS で OPTIONS Lambda 不要に) - Ruby 3.3 → Node.js 20 ARM64 (TypeScript) で他 infra と言語統一 - scratch-api-proxy/projects のステータスコード透過バグを修正 (旧実装は Net::HTTP.get でボディだけ取得 → 常に 200 だった) - mesh-zone-get の secret key を環境変数化 (旧実装はハードコード) - stg 環境を新設 (旧実装は prod のみ) - 23 ユニットテスト追加 (mock fetch) stg デプロイ完了: - Custom domain: https://stg.api.smalruby.app - 検証: 公開済みプロジェクトは 200, 存在しないプロジェクトは 404, CORS preflight は 204 + 適切なヘッダー、translate も透過動作 prod カットオーバーは別作業 (旧 SAM スタックのドメイン解放と協調が必要): 1. .env.prod に旧 secret_key を設定 (mesh domain identity を維持) 2. SAM スタック smalruby-infra-prod のドメインマッピング解除 3. cdk deploy --context stage=prod 4. SAM スタック decommission Refs: #573
- .github/workflows/ci-infra.yml: rubytee-relay と同形式の 3 ジョブを追加 - smalruby-api-unit-tests (npm test) - smalruby-api-cdk-build (build + cdk synth、ダミー env で実行) - smalruby-api-security (npm audit) - jest.config.js: integration test を unit から除外 (.integration.test.ts) - jest.integration.config.js を追加 (rubytee-relay と同様) - package.json に test:integration スクリプト追加 - lambda/tests/*.integration.test.ts × 4 を追加 (合計 18 テスト) - scratch-api-projects: 200/404/CORS/不許可 origin (Issue #573 デグレ防止) - scratch-api-translate: 200/400/特殊文字エンコード/CORS - mesh-zone-get: hex domain 形式/決定性/CORS - cors-proxy: text 透過/PNG バイナリ/不正スキーム/CORS stg エンドポイントに対して 18 テスト全パスを確認。
URL ローダーの失敗時、proxy のステータスコードに応じた具体的なエラーを モーダル内に表示するようにする。Issue #573 の本丸 UX バグ修正。 修正前の挙動: - proxy が 200/404/403/500 何を返してもアラートで「プロジェクトURLの読み 込みに失敗しました。」を表示するのみ - モーダル内のエラー表示は invalidUrl のメッセージで固定 (state.error の 内容は無視) 修正後の挙動: - proxy 修正前と修正後の両方に対応 (data.code === 'NotFound' 互換チェック) - 404 → 「プロジェクトが見つかりません。共有が解除されたか、URLが間違って いる可能性があります。」 - 403 → 「このプロジェクトにはアクセスできません。」 - 5xx → 「Scratchサーバー側でエラーが発生しました。しばらく経ってから再度 お試しください。」 - TypeError (ネットワーク失敗) → 「ネットワークエラーが発生しました。」 - proxy が 200 + project_token なし → 502 扱い - 不正な URL → 既存の「有効なScratchプロジェクトURL...」メッセージ - モーダルは送信時にクローズせず、成功時のみクローズ。失敗時はメッセージ を表示してリトライさせる 実装上の構造変更: - src/lib/url-loader.js を新設し、formatLoadError と fetchProjectInfo を pure function として分離 (HOC からテスト容易な形に) - src/lib/url-loader-hoc.jsx は React/Redux 連携の thin wrapper に縮小 - url-loader-modal.jsx の固定 FormattedMessage を動的 error string 表示に - ロケール (ja, ja-Hira, en) に 4 つの新メッセージ追加 - data-testid="url-loader-error" を追加 (integration test 用) エンドポイント設定: - SCRATCH_API_PROXY_ENDPOINT 環境変数を追加 - デフォルト: https://api.smalruby.app (prod) - ローカル開発時は .env で https://stg.api.smalruby.app に上書き - webpack.config.js の DefinePlugin で注入 (Smalruby マーカー付き) - .github/workflows/ci-cd.yml の build-and-deploy 3 ジョブ全部に追加 (vars.SCRATCH_API_PROXY_ENDPOINT) テスト: src/lib/url-loader.test.js に 18 ユニットテスト追加 - formatLoadError × 8 (404 / 403 / 5xx / TypeError / fallback) - fetchProjectInfo × 10 (各 status / legacy NotFound / token 欠損 / 特殊文字エンコード / TypeError 透過) stg エンドポイントを使った Playwright 動作確認: - 不正 URL → モーダル内に invalidUrl メッセージ表示 ✓ - 9999999999 (404) → 「プロジェクトが見つかりません」表示 ✓ - 108317385 (正常) → モーダル閉じてプロジェクトロード ✓ Refs: #573
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/fix/scratch-url-loader-error-messages/ |
github-actions Bot
pushed a commit
that referenced
this pull request
Apr 29, 2026
…rl-loader-error-messages fix: Scratch URL loader migrates to CDK proxy and shows specific error messages
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Issue #573 (「Scratchから読み込む」が機能しない) の根本修正。原因は二重バグだった:
lambda/smalruby-scratch-api-proxy-get-project-info/lambda_function.rbがNet::HTTP.get(ボディのみ取得) を使っていて、Scratch API が 404/403 を返しても常に statusCode 200 を返していたurl-loader-modal.jsxがエラー内容に関わらず固定メッセージinvalidUrlErrorを表示していた両方を一本の PR で修正。proxy の機会を活かして既存 SAM スタック (
smalruby-infra-prod) を CDK に移行し、stg 環境も新設した。Changes
1. infra/smalruby-api/ (新規 CDK プロジェクト)
旧 SAM 実装 (
smalruby/smalruby-infraリポジトリ) の 4 エンドポイントを TypeScript Lambda + HTTP API v2 で再実装:/cors-proxysmalruby-cors-proxy/mesh-domainsmalruby-mesh-zone-get/scratch-api-proxy/projects/{projectId}smalruby-scratch-api-projects/scratch-api-proxy/translatesmalruby-scratch-api-translate主な変更点:
stg.api.smalruby.app)stg 環境はデプロイ済み (https://stg.api.smalruby.app)。
2. CI + integration tests
.github/workflows/ci-infra.ymlに 3 ジョブ追加 (rubytee-relay と同形式)3. frontend url-loader 修正
src/lib/url-loader.jsを新設し、formatLoadErrorとfetchProjectInfoを pure function として分離200 + {code:"NotFound"}) との 後方互換 も実装 (proxy デプロイ前後どちらでも動く)4. 環境変数追加
SCRATCH_API_PROXY_ENDPOINTを webpack DefinePlugin + ci-cd.yml の build-and-deploy 全 3 ジョブに追加vars.SCRATCH_API_PROXY_ENDPOINT=https://api.smalruby.app).envでhttps://stg.api.smalruby.appに上書き動作確認
stg curl テスト
Playwright (dev server, stg エンドポイント使用)
Test plan
infra/smalruby-apiユニットテスト 23 通過 (lint warning なし)infra/smalruby-apiintegration テスト 18 通過 (stg)packages/scratch-guiユニットテスト (url-loader.test.js) 18 通過packages/scratch-guilint 通過 (zero warnings)prod カットオーバー (本 PR のスコープ外)
旧 SAM スタック (
smalruby-infra-prod) と CDK 新スタックは 当面共存 する。prod ドメインapi.smalruby.appは SAM が保持。後続作業:MESH_ZONE_SECRET_KEYを旧 SAM のuXM1VAA6MO39yJ+djz4kbpVGy3Rg1V3Zでinfra/smalruby-api/.env.prodに設定cdk deploy --context stage=prodで新スタックをapi.smalruby.appに紐付けRelated
Closes #573
Refs #572 (iOS Safari 対応は別 PR / 別 Issue)