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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

この版は promidas 5.x 向けです。

### BREAKING CHANGES

- **Peer dependency**: `promidas` の要件を `^5.0.0` に変更しました (以前は `^4.0.0`)
- `promidas` 4.x を使う場合は `promidas-utils` 4.x を使ってください
- **リポジトリ**: promidas 5 の失敗の変更に対応しました
- `CORS_BLOCKED` の文言は `BROWSER_FETCH_FAILED` に表示されます
- `[参考情報]` の `通信エラーコード` は `details.causeCode` を表示します。promidas が作った値 (`TIMEOUT` など) は届かなくなりました

## [4.0.0] - 2026-11-09

この版は promidas 4.x 向けです。
Expand Down
8 changes: 4 additions & 4 deletions docs/api/repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ APIリクエストの失敗時に生成されるメッセージ。以下の情
- HTTPステータスコード (400, 404, 500など)
- エラーコード (CLIENT_ERROR, SERVER_ERROR, NETWORK_ERROR, TIMEOUT など)
- 分類 (kind)
- 通信エラーコード (UND_ERR_SOCKET など。エラーコードと異なる場合のみ)
- 通信エラーコード (`details.causeCode`。UND_ERR_SOCKET など。エラーコードと異なる場合のみ)
- リクエスト情報 (メソッド、URL)
- レスポンス情報 (ステータスコード、ステータステキスト)

Expand All @@ -105,11 +105,11 @@ APIリクエストの失敗時に生成されるメッセージ。以下の情
- `"サーバーの応答を処理できませんでした。応答の形式が正しくない可能性があります。"` (正常なステータスで、応答を処理できない場合)
- `"ネットワークエラーが発生しました。\n次のような原因が考えられます:\n- ネットワークがオフライン\n- 通信が途中で切断された\n- サーバーが一時的に利用できない\n- ファイアウォールやプロキシの設定"`
- `"リクエストがタイムアウトしました。\n次を試してください:\n- ネットワーク接続を確認する\n- limitパラメータを減らす\n- timeoutMs を長くする (設定できる場合)"` (`TIMEOUT`)
- `"APIサーバーとの通信に失敗しました。\nブラウザの制限により、原因を特定できません。\n次のような原因が考えられます:\n- APIトークンが無効 (認証エラーはこの表示になります)\n- ネットワークがオフライン\n- サーバーに接続できない"` (`CORS_BLOCKED`)
- `"APIサーバーとの通信に失敗しました。\nブラウザの制限により、原因を特定できません。\n次のような原因が考えられます:\n- APIトークンが無効 (認証エラーはこの表示になります)\n- ネットワークがオフライン\n- サーバーに接続できない"` (`BROWSER_FETCH_FAILED`)

#### `CORS_BLOCKED` の原因の調べ方
#### `BROWSER_FETCH_FAILED` の原因の調べ方

`CORS_BLOCKED` は、CORS が原因だと判定した結果ではありません。ブラウザの `fetch` が JavaScript に応答を渡さずに失敗したことを表します。
`BROWSER_FETCH_FAILED` は、原因を判定した結果ではありません。ブラウザの `fetch` が JavaScript に応答を渡さずに失敗したことを表します。

ブラウザは、無効なトークン (401)、CORS のブロック、接続の失敗を、JavaScript には同じエラーとして渡します。そのため、`promidas` でも `promidas-utils` でも原因を特定できません。

Expand Down
12 changes: 9 additions & 3 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ instructions-for-ais:

- Node.js 22 以降
- npm 9 以降 (推奨 npm 10 以降)
- `promidas` 4.0.0 以降の 4.x
- `promidas` 5.0.0 以降の 5.x

`promidas` 3.x を使う場合は `promidas-utils` 3.x を使ってください。
以前の `promidas` を使う場合は、対応する `promidas-utils` を使ってください。

| `promidas` | `promidas-utils` |
| ---------- | ---------------- |
| 5.x | 5.x |
| 4.x | 4.x |
| 3.x | 3.x |

## インストール

Expand All @@ -31,7 +37,7 @@ npm install promidas-utils
### 特定バージョンのインストール

```bash
npm install promidas-utils@4.0.0
npm install promidas-utils@5.0.0
```

## 更新
Expand Down
12 changes: 6 additions & 6 deletions lib/repository/snapshot-operation-failure-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export function parseFetcherSnapshotFailure(
lines.push(`リクエスト: ${[method, url].filter(Boolean).join(' ')}`);
}

const { statusText, code: networkCode } = failure.details.res ?? {};
const { statusText } = failure.details.res ?? {};
const { causeCode } = failure.details;
if (failure.status || statusText) {
if (failure.status) {
lines.push(
Expand All @@ -65,10 +66,9 @@ export function parseFetcherSnapshotFailure(
if (failure.kind) {
lines.push(`分類: ${failure.kind}`);
}
// `details.res.code` does not come from a response: it identifies the failure
// at the network layer (e.g. UND_ERR_SOCKET). Only show it when it adds something.
if (networkCode && networkCode !== failure.code) {
lines.push(`通信エラーコード: ${networkCode}`);
// The code found on the error (e.g. UND_ERR_SOCKET). Only show it when it adds something.
if (causeCode && causeCode !== failure.code) {
lines.push(`通信エラーコード: ${causeCode}`);
}

// Keep raw message as-is for stability (no parsing).
Expand Down Expand Up @@ -235,7 +235,7 @@ export function parseFetcherSnapshotFailure(
return withFetcherReferenceInfo('リクエストがキャンセルされました。');

// Browsers report a CORS block and a failed connection with the same error.
case 'CORS_BLOCKED':
case 'BROWSER_FETCH_FAILED':
return withFetcherReferenceInfo(
[
'APIサーバーとの通信に失敗しました。',
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"docs:preview": "vitepress preview docs"
},
"peerDependencies": {
"promidas": "^4.0.0"
"promidas": "^5.0.0"
},
"devDependencies": {
"@types/eslint": "^9.6.1",
Expand All @@ -62,7 +62,7 @@
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-import-x": "^4.18.0",
"prettier": "^3.9.10",
"promidas": "^4.0.0",
"promidas": "^5.0.0",
"rimraf": "^6.1.4",
"ts-essentials": "^10.2.1",
"typescript": "^5.9.3",
Expand Down
39 changes: 15 additions & 24 deletions test/repository/snapshot-operation-failure-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,12 +574,12 @@ describe('snapshot-operation-failure-utils', () => {
});

describe('CORS errors', () => {
it('should handle CORS_BLOCKED', () => {
it('should handle BROWSER_FETCH_FAILED', () => {
const failure: FetcherSnapshotFailure = {
ok: false,
origin: 'fetcher',
kind: 'cors',
code: 'CORS_BLOCKED',
kind: 'browser_fetch',
code: 'BROWSER_FETCH_FAILED',
message: 'CORS blocked',
details: { req: {}, res: {} },
};
Expand Down Expand Up @@ -665,9 +665,7 @@ describe('snapshot-operation-failure-utils', () => {
message: 'Failed to read the response body',
details: {
req: {},
res: {
code: 'UND_ERR_SOCKET',
},
causeCode: 'UND_ERR_SOCKET',
},
};

Expand All @@ -680,43 +678,36 @@ describe('snapshot-operation-failure-utils', () => {
const failure: FetcherSnapshotFailure = {
ok: false,
origin: 'fetcher',
kind: 'timeout',
code: 'TIMEOUT',
message: 'Upstream request timed out',
kind: 'network',
code: 'ECONNREFUSED',
message: 'fetch failed',
details: {
req: {},
res: {
code: 'TIMEOUT',
},
causeCode: 'ECONNREFUSED',
},
};

const result = parseFetcherSnapshotFailure(failure);
expect(result).toContain('エラーコード: TIMEOUT');
expect(result).toContain('エラーコード: ECONNREFUSED');
expect(result).not.toContain('通信エラーコード');
});

it('should list the reference info in the same order as other failures', () => {
const failure: FetcherSnapshotFailure = {
ok: false,
origin: 'fetcher',
kind: 'cors',
code: 'CORS_BLOCKED',
kind: 'browser_fetch',
code: 'BROWSER_FETCH_FAILED',
message: 'Failed to fetch',
details: {
res: {
code: 'NETWORK_ERROR',
},
},
details: {},
};

const result = parseFetcherSnapshotFailure(failure);
expect(result).toContain(
[
'[参考情報]',
'エラーコード: CORS_BLOCKED',
'分類: cors',
'通信エラーコード: NETWORK_ERROR',
'エラーコード: BROWSER_FETCH_FAILED',
'分類: browser_fetch',
'詳細: Failed to fetch',
].join('\n'),
);
Expand Down Expand Up @@ -1250,7 +1241,7 @@ describe('snapshot-operation-failure-utils', () => {
status: 401,
details: {
req: { method: 'GET', url: 'https://api.example.com/data' },
res: { statusText: 'Unauthorized', code: 'UNAUTHORIZED' },
res: { statusText: 'Unauthorized' },
},
};

Expand Down
Loading