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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,9 @@ function uploadMedia(params: UploadMediaRequest): Promise<{ url: string }>;

## エラーハンドリング

microCMS APIへのリクエストに失敗した場合は、`isMicroCMSRequestError`を使用して、HTTPステータスコード、リクエスト先URL、元のネットワークエラーを参照できます。
microCMS APIへのリクエストに失敗した場合、エラーは通常の`Error`として扱えます。`console.error(error)`でエラーメッセージとスタックトレースを出力でき、HTTPエラーの場合はHTTPステータスとAPIから返されたエラーメッセージも含まれます。

さらに、`isMicroCMSRequestError`でエラーを判定すると、リクエストに関する追加情報として`status`、`url`、`originalError`を個別に参照できます。

```typescript
import { createClient, isMicroCMSRequestError } from 'microcms-js-sdk';
Expand All @@ -738,8 +740,6 @@ try {
}
```

`console.error(error)`でエラーメッセージとスタックトレースを出力できます。HTTPエラーの場合、メッセージにはHTTPステータスとAPIから返されたエラーメッセージが含まれます。`status`、`url`、`originalError`は、必要に応じて個別に参照できる追加情報です。

| プロパティ | HTTPエラー | ネットワークエラー |
| --------------- | ----------------------------- | --------------------------- |
| `status` | HTTPステータスコード | `undefined` |
Expand Down
6 changes: 3 additions & 3 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,9 @@ function uploadMedia(params: UploadMediaRequest): Promise<{ url: string }>;

## Error handling

When a request to the microCMS API fails, use `isMicroCMSRequestError` to access the HTTP status code, request URL, and original network error.
When a request to the microCMS API fails, the error can be handled as a standard `Error`. `console.error(error)` logs the error message and stack trace. For HTTP errors, the output also includes the HTTP status and the error message returned by the API.

Additionally, after narrowing the error with `isMicroCMSRequestError`, you can access `status`, `url`, and `originalError` as structured request details.

```typescript
import { createClient, isMicroCMSRequestError } from 'microcms-js-sdk';
Expand All @@ -738,8 +740,6 @@ try {
}
```

`console.error(error)` logs the error message and stack trace. For HTTP errors, the message includes the HTTP status and the error message returned by the API. `status`, `url`, and `originalError` are additional details that can be accessed individually when needed.

| Property | HTTP error | Network error |
| --------------- | ---------------- | ------------------------------ |
| `status` | HTTP status code | `undefined` |
Expand Down