{"id":473890,"date":"2025-09-04T09:00:12","date_gmt":"2025-09-04T09:00:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=473890"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=473890","title":{"rendered":"<span>\u0425\u0432\u0430\u0442\u0438\u0442 \u043f\u0438\u0441\u0430\u0442\u044c try\/catch \u0432\u043e\u043a\u0440\u0443\u0433 fetch: \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u044f \u0443\u0441\u0442\u0430\u043b \u043b\u043e\u0432\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/t2\/xz\/za\/t2xzzaxzweeqm8rmtmi6hhtslim.jpeg\" alt=\"&quot;You can't have errors in your code if you wrap the entire codebase in a try\/catch block&quot;\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/t2\/xz\/za\/t2xzzaxzweeqm8rmtmi6hhtslim.jpeg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/t2\/xz\/za\/t2xzzaxzweeqm8rmtmi6hhtslim.jpeg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>&#171;You can&#8217;t have errors in your code if you wrap the entire codebase in a try\/catch block&#187;<\/figcaption><\/div>\n<\/figure>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u043c \u0441\u043c\u0435\u0448\u043d\u043e\u0439, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0441\u043e\u0437\u043d\u0430\u0435\u0448\u044c, \u0447\u0442\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043c\u044b \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u043c. \u0422\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0435 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0441\u0440\u0430\u0437\u0443, \u0430 \u043a\u0430\u0436\u0434\u044b\u0439 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u0438\u0448\u0435\u0448\u044c <code>fetch<\/code> \u0438 \u0440\u0435\u0444\u043b\u0435\u043a\u0442\u043e\u0440\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0448\u044c <code>try\/catch<\/code>. \u0413\u0434\u0435-\u0442\u043e \u0441\u043b\u043e\u0432\u0438\u043b <code>TypeError<\/code>, \u0433\u0434\u0435-\u0442\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442, \u0433\u0434\u0435-\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u0435\u0440\u043d\u0443\u043b 500. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u043a\u043e\u0434\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0448\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 &#8212; \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<p>\u042f \u0433\u043e\u0434\u0430\u043c\u0438 \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u043b, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u043d\u044f\u043b: \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043d\u0435 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043b\u043e\u0432\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0438. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <code>fetch<\/code> \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0441 \u0438\u0445 \u043b\u043e\u0432\u0438\u0442\u044c \u0432\u0435\u0437\u0434\u0435 \u0438 \u0432\u0441\u0435\u0433\u0434\u0430.<\/p>\n<p>\u0422\u0430\u043a \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <strong><a class=\"mention\" href=\"\/users\/asouei\">@asouei<\/a>\/safe-fetch<\/strong>. \u0415\u0435 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0441\u0442\u0430: \u0443\u0431\u0440\u0430\u0442\u044c <code>try\/catch<\/code> \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430.<\/p>\n<h3>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u0430\u043b\u0438 \u0432\u0441\u0435\u0445<\/h3>\n<p>\u041f\u043e\u043c\u043d\u0438\u0442\u0435 \u044d\u0442\u0443 \u043a\u0440\u0430\u0441\u043e\u0442\u0443?<\/p>\n<pre><code class=\"typescript\">try {   const res = await fetch('\/api\/users');   if (!res.ok) {     throw new Error(`HTTP ${res.status}: ${res.statusText}`);   }   const data = await res.json();   \/\/ \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0441 data } catch (e) {   \/\/ \u0430 \u0442\u0443\u0442 \u043b\u043e\u0432\u0438\u043c \u0432\u0441\u0435 \u043f\u043e\u0434\u0440\u044f\u0434: \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b, 404, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0441\u0435\u0442\u044c\u044e   console.error('\u0427\u0442\u043e-\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a:', e.message); } <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/w1\/28\/ej\/w128ej76yfcyxtw0cj0gukjzvku.jpeg\" alt=\"\u041c\u0435\u043c \u043f\u0440\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a: exception \u0432 \u0432\u0438\u0434\u0435 \u043c\u0435\u0434\u0432\u0435\u0434\u044f, \u0430 try, catch \u0438 finally \u0443\u0431\u0435\u0433\u0430\u044e\u0442 \u043e\u0442 \u043d\u0435\u0433\u043e\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/w1\/28\/ej\/w128ej76yfcyxtw0cj0gukjzvku.jpeg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/w1\/28\/ej\/w128ej76yfcyxtw0cj0gukjzvku.jpeg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041c\u0435\u043c \u043f\u0440\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a: exception \u0432 \u0432\u0438\u0434\u0435 \u043c\u0435\u0434\u0432\u0435\u0434\u044f, \u0430 try, catch \u0438 finally \u0443\u0431\u0435\u0433\u0430\u044e\u0442 \u043e\u0442 \u043d\u0435\u0433\u043e<\/figcaption><\/div>\n<\/figure>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043c\u0435\u0441\u044f\u0446 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a. \u0410 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435:<\/p>\n<ul>\n<li>\n<p><code>fetch<\/code> \u043a\u0438\u0434\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0441\u0431\u043e\u0438. 404 \u0438 500 \u043d\u0430\u0434\u043e \u043b\u043e\u0432\u0438\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0442 &#171;\u043e\u0431\u0449\u0435\u0433\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430&#187; \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e. \u0422\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0441\u0442\u044b\u043b\u0438 \u0441 <code>AbortController<\/code><\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0433\u0438\u043a\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043e\u0432? \u041f\u0438\u0448\u0438 \u0441\u0430\u043c \u0438\u043b\u0438 \u0442\u0430\u0449\u0438 \u0442\u044f\u0436\u0435\u043b\u044b\u0439 axios<\/p>\n<\/li>\n<li>\n<p>\u041e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b. \u0412 TypeScript \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0433\u0430\u0434\u0430\u0442\u044c \u0447\u0442\u043e \u0432 <code>e.message<\/code><\/p>\n<\/li>\n<\/ul>\n<h3>\u0427\u0442\u043e \u044f \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c<\/h3>\n<p>\u0422\u0440\u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0432\u0435\u0449\u0438:<\/p>\n<p><strong>1. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 throw<\/strong><br \/> \u041a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u0444\u043b\u0430\u0433\u043e\u043c <code>ok<\/code>.<\/p>\n<p><strong>2. \u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/strong><br \/> \u0412\u043c\u0435\u0441\u0442\u043e \u0437\u0430\u0433\u0430\u0434\u043e\u0447\u043d\u043e\u0433\u043e <code>e.message<\/code> &#8212; \u0447\u0435\u0442\u043a\u0438\u0435 \u0442\u0438\u043f\u044b: <code>NetworkError<\/code>, <code>TimeoutError<\/code>, <code>HttpError<\/code>, <code>ValidationError<\/code>.<\/p>\n<p><strong>3. \u0424\u0438\u0448\u043a\u0438 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438<\/strong><br \/> \u041e\u0431\u0449\u0438\u0439 \u0442\u0430\u0439\u043c\u0430\u0443\u0442, \u0443\u043c\u043d\u044b\u0435 \u0440\u0435\u0442\u0440\u0430\u0438, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 <code>Retry-After<\/code>.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442:<\/p>\n<pre><code class=\"typescript\">import { safeFetch } from '@asouei\/safe-fetch';  const result = await safeFetch.get&lt;{ users: User[] }&gt;('\/api\/users');  if (result.ok) {   console.log(result.data.users); } else {   console.error(result.error.name); \/\/ NetworkError | TimeoutError | ... } <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u0439: \u043b\u0438\u0431\u043e <code>{ ok: true, data }<\/code>, \u043b\u0438\u0431\u043e <code>{ ok: false, error }<\/code>.<br \/> \u041d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e <code>try\/catch<\/code> \u0432 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0435.<\/p>\n<h3>\u0427\u0442\u043e \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c<\/h3>\n<h4>\u0414\u0432\u043e\u0439\u043d\u044b\u0435 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b<\/h4>\n<p>\u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c <code>timeoutMs<\/code> \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0438 <code>totalTimeoutMs<\/code> \u0434\u043b\u044f \u0432\u0441\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"typescript\">const api = createSafeFetch({   timeoutMs: 5000,        \/\/ 5\u0441 \u043d\u0430 \u043f\u043e\u043f\u044b\u0442\u043a\u0443   totalTimeoutMs: 30000   \/\/ 30\u0441 \u0432\u0441\u0435\u0433\u043e (\u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0440\u0435\u0442\u0440\u0430\u0438) }); <\/code><\/pre>\n<h4>\u0423\u043c\u043d\u044b\u0435 \u0440\u0435\u0442\u0440\u0430\u0438<\/h4>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e <code>GET<\/code> \u0438 <code>HEAD<\/code> &#8212; \u044d\u0442\u043e \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 POST-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432:<\/p>\n<pre><code class=\"typescript\">const result = await safeFetch.get('\/api\/flaky', {   retries: {     retries: 3,     baseDelayMs: 300  \/\/ \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 backoff   } }); <\/code><\/pre>\n<h4>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 Retry-After<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u0435\u0440\u043d\u0443\u043b 429 \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c &#8212; \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u0430\u043c\u0430 \u043f\u043e\u0434\u043e\u0436\u0434\u0435\u0442:<\/p>\n<pre><code class=\"typescript\">\/\/ \u0421\u0435\u0440\u0432\u0435\u0440: 429 Too Many Requests, Retry-After: 60 \/\/ safe-fetch: \u0436\u0434\u0435\u043c \u0440\u043e\u0432\u043d\u043e 60 \u0441\u0435\u043a\u0443\u043d\u0434 <\/code><\/pre>\n<h4>Validation \u0431\u0435\u0437 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/h4>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c Zod \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0445\u0435\u043c\u0443:<\/p>\n<pre><code class=\"typescript\">const result = await safeFetch.get('\/user\/123', {   validate: (data) =&gt; UserSchema.safeParse(data).success      ? { success: true, data }      : { success: false, error: 'Invalid user' } }); <\/code><\/pre>\n<h3>\u0420\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u043b\u044c\u0437\u0430<\/h3>\n<h4>\u0414\u043e: \u043a\u043e\u0434\u043e\u0432\u0430\u044f \u0431\u0430\u0437\u0430 \u0438\u0437 \u0430\u0434\u0430<\/h4>\n<pre><code class=\"typescript\">async function getUsers() {   try {     const res = await fetch('\/api\/users');     if (!res.ok) throw new Error(`${res.status}`);     return await res.json();   } catch (e) {     logger.error('Users fetch failed', e);     throw e; \/\/ \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435   } }  async function createUser(data) {   try {     const res = await fetch('\/api\/users', {       method: 'POST',       body: JSON.stringify(data)     });     if (!res.ok) throw new Error(`${res.status}`);     return await res.json();   } catch (e) {     logger.error('User creation failed', e);     throw e;   } } <\/code><\/pre>\n<h4>\u041f\u043e\u0441\u043b\u0435: \u0447\u0438\u0441\u0442\u044b\u0439 \u043a\u043e\u0434<\/h4>\n<pre><code class=\"typescript\">const api = createSafeFetch({   baseURL: '\/api',   interceptors: {     onError: (error) =&gt; logger.error('API error', error)   } });  async function getUsers() {   return api.get&lt;User[]&gt;('\/users'); }  async function createUser(data: NewUser) {   return api.post&lt;User&gt;('\/users', data); } <\/code><\/pre>\n<p>\u0412\u0435\u0441\u044c error handling \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0445\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a.<\/p>\n<h3>\u0418\u0441\u0442\u043e\u0440\u0438\u044f \u0438\u0437 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438<\/h3>\n<p>\u0423 \u043c\u0435\u043d\u044f \u0431\u044b\u043b \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435, \u0433\u0434\u0435 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043c\u0438 API. \u041d\u0430 \u0431\u0443\u043c\u0430\u0433\u0435 \u0432\u0441\u0451 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u043f\u0440\u043e\u0441\u0442\u043e: \u0434\u0435\u0440\u0433\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435. \u041d\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u0441\u0451 \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u043b\u0430.<\/p>\n<p><strong>\u0427\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u043b 500-\u043c\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u043b\u044e\u0431\u0438\u043b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u0435 JSON-\u044b, \u0445\u043e\u0442\u044f \u0441\u0442\u0430\u0442\u0443\u0441 \u0431\u044b\u043b 200<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043e\u0442\u0432\u0435\u0442\u044b \u0437\u0430\u0432\u0438\u0441\u0430\u043b\u0438 \u043d\u0430 \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0441\u0435\u043a\u0443\u043d\u0434, \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0436\u0430\u043b\u043e\u0432\u0430\u043b\u0438\u0441\u044c, \u0447\u0442\u043e \u00ab\u043a\u043d\u043e\u043f\u043a\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u00bb<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043a\u043e\u0434 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043b\u0441\u044f \u0432 \u0445\u0430\u043e\u0441 \u0438\u0437 <code>try\/catch<\/code>, \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432 \u0441 <code>AbortController<\/code> \u0438 \u043a\u0443\u0447\u0438 \u043b\u043e\u0433\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 \u00abRequest failed again\u00bb. \u041c\u044b \u0434\u0430\u0436\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u0438\u0434\u0435\u044e \u0442\u0430\u0449\u0438\u0442\u044c axios, \u0445\u043e\u0442\u044f \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0433\u043e\u0440\u0435\u043b \u0436\u0435\u043b\u0430\u043d\u0438\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u0442\u044f\u0436\u0435\u043b\u0443\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c.<\/p>\n<p>\u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u0441\u043e\u0431\u0440\u0430\u043b\u0441\u044f \u0438 \u0441\u043a\u0430\u0437\u0430\u043b: \u00ab\u0425\u0432\u0430\u0442\u0438\u0442. \u041c\u044b \u0442\u0440\u0430\u0442\u0438\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u043b\u043e\u0432\u043b\u044e \u043e\u0448\u0438\u0431\u043e\u043a, \u0447\u0435\u043c \u043d\u0430 \u0444\u0438\u0447\u0438\u00bb. \u0422\u0430\u043a \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f safe-fetch.<\/p>\n<p><strong>\u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0412\u0435\u0441\u044c error handling \u0443\u0435\u0445\u0430\u043b \u0432 interceptors &#8212; \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0433\u0434\u0435 \u0438\u0441\u043a\u0430\u0442\u044c \u0431\u0430\u0433\u0438<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0442\u0440\u0430\u0438 \u043d\u0430 GET \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0441\u043f\u0430\u0441\u043b\u0438 \u043e\u0442 \u0444\u043b\u0435\u0439\u043a\u0438 API (\u0440\u0430\u043d\u044c\u0448\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u0444\u0440\u0435\u0448\u0438\u043b\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443)<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0449\u0438\u0439 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u0438\u0437\u0431\u0430\u0432\u0438\u043b \u043e\u0442 \u00ab\u0432\u0435\u0447\u043d\u044b\u0445\u00bb \u0441\u043f\u0438\u043d\u043d\u0435\u0440\u043e\u0432, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0436\u0434\u0430\u043b \u043e\u0442\u0432\u0435\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u0440\u0438\u0434\u0451\u0442<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043b\u043e\u0433\u0430\u0445 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0432\u043d\u044f\u0442\u043d\u044b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a (<code>NetworkError<\/code>, <code>TimeoutError<\/code>), \u0430 \u043d\u0435 \u0437\u0430\u0433\u0430\u0434\u043e\u0447\u043d\u044b\u0435 \u00abundefined\u00bb<\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u043d\u0435\u0434\u0435\u043b\u044c \u043c\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 <strong>\u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043f\u0438\u0448\u0435\u043c try\/catch \u0432\u043e\u043a\u0440\u0443\u0433 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/strong>. \u0418 \u044d\u0442\u043e \u0441\u0442\u0430\u043b\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u0432\u0441\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<h3>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u0430\u043c\u0438<\/h3>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u0424\u0438\u0447\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">safe-fetch<\/p>\n<\/th>\n<th>\n<p align=\"left\">axios<\/p>\n<\/th>\n<th>\n<p align=\"left\">ky<\/p>\n<\/th>\n<th>\n<p align=\"left\">fetch<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0420\u0430\u0437\u043c\u0435\u0440<\/p>\n<\/td>\n<td>\n<p align=\"left\">~3kb<\/p>\n<\/td>\n<td>\n<p align=\"left\">~13kb<\/p>\n<\/td>\n<td>\n<p align=\"left\">~11kb<\/p>\n<\/td>\n<td>\n<p align=\"left\">0kb<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2705<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0422\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2705<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041e\u0431\u0449\u0438\u0439 \u0442\u0430\u0439\u043c\u0430\u0443\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2705<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Retry-After<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2705<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Zod-ready<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2705<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043f\u0435\u0440\u0432\u044b\u0435 \u0448\u0430\u0433\u0438<\/h3>\n<pre><code class=\"bash\">npm install @asouei\/safe-fetch <\/code><\/pre>\n<p>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"typescript\">import { safeFetch } from '@asouei\/safe-fetch';  const users = await safeFetch.get&lt;User[]&gt;('\/api\/users'); if (users.ok) {   console.log(users.data); } else {   console.error(users.error.name, users.error.message); } <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"typescript\">import { createSafeFetch } from '@asouei\/safe-fetch';  const api = createSafeFetch({   baseURL: 'https:\/\/api.example.com',   headers: { 'Authorization': `Bearer ${token}` },   timeoutMs: 10000,   retries: { retries: 2 } }); <\/code><\/pre>\n<h3>\u0414\u043b\u044f \u043a\u043e\u0433\u043e \u044d\u0442\u043e<\/h3>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u044b, \u0443\u0441\u0442\u0430\u0432\u0448\u0438\u0435 \u043e\u0442 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442\u044b \u0441 \u0436\u0435\u0441\u0442\u043a\u0438\u043c\u0438 SLA, \u0433\u0434\u0435 \u0432\u0430\u0436\u043d\u044b \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b \u0438 \u0440\u0435\u0442\u0440\u0430\u0438<\/p>\n<\/li>\n<li>\n<p>TypeScript-\u043a\u043e\u0434\u0431\u0430\u0437\u044b, \u0433\u0434\u0435 \u043d\u0443\u0436\u043d\u0430 \u0442\u043e\u0447\u043d\u0430\u044f \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u044f\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0443 fetch \u0441 production-\u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u044c\u044e<\/p>\n<\/li>\n<\/ul>\n<h3>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435<\/h3>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u0430 \u043a \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0443. \u0412 \u043f\u043b\u0430\u043d\u0430\u0445:<\/p>\n<ul>\n<li>\n<p>ESLint \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0434\u043b\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 <code>{ ok }<\/code><\/p>\n<\/li>\n<li>\n<p>\u0413\u043e\u0442\u043e\u0432\u044b\u0435 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u044b \u0434\u043b\u044f React Query \u0438 SWR<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u043b\u044f Next.js \u0438 Cloudflare Workers<\/p>\n<\/li>\n<\/ul>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435 \u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b \u044d\u0442\u0443 \u0448\u0442\u0443\u043a\u0443 \u0434\u043b\u044f \u0441\u0435\u0431\u044f, \u0447\u0442\u043e\u0431\u044b \u0441\u0430\u043c\u043e\u043c\u0443 \u0431\u044b\u043b\u043e \u043b\u0435\u0433\u0447\u0435. \u041d\u043e \u0432\u0441\u043a\u043e\u0440\u0435 \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 &#8212; \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p><strong>safe-fetch<\/strong> \u043d\u0435 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c axios \u0438\u043b\u0438 ky. \u041e\u043d\u0430 \u0440\u0435\u0448\u0430\u0435\u0442 \u043e\u0434\u043d\u0443 \u0437\u0430\u0434\u0430\u0447\u0443: \u0434\u0435\u043b\u0430\u0435\u0442 fetch \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u0439 &#8212; \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0431\u0438\u0440\u0430\u0435\u0442 \u0442\u0443 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u0443\u044e \u0431\u043e\u043b\u044c, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0432\u0441\u0435 \u0441\u043c\u0438\u0440\u0438\u043b\u0438\u0441\u044c.<\/p>\n<p>\u041c\u043e\u0436\u0435\u0442, \u0432\u044b \u0442\u043e\u0436\u0435 \u0443\u0441\u0442\u0430\u043b\u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c \u0434\u0436\u0443\u043d\u0430\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c <code>res.ok<\/code>? \u0418\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u043a\u0430\u0436\u0434\u043e\u043c API-\u043c\u0435\u0442\u043e\u0434\u0435? \u0415\u0441\u043b\u0438 \u0434\u0430 &#8212; \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0434\u0435\u043b\u044e \u0432\u044b \u0443\u0436\u0435 \u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0441\u0442\u0430\u0440\u044b\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c.<\/p>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0431\u0430\u0433\u0438 \u0438\u043b\u0438 \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0447\u0442\u043e-\u0442\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c &#8212; \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 Issues. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u044d\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u043e\u0434\u0438\u043b\u0430\u0441\u044c \u0438\u0437 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0438 \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u043d\u0430 \u0440\u0430\u0441\u0442\u0435\u0442 \u043e\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0438\u0434\u0431\u0435\u043a\u0430.<\/p>\n<ul>\n<li>\n<p>\ud83c\udf1f \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 <a href=\"https:\/\/github.com\/dzharii\/awesome-typescript\" rel=\"noopener noreferrer nofollow\">Awesome TypeScript<\/a> \u2014 \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u0440\u0443\u043f\u043d\u0435\u0439\u0448\u0438\u0445 \u043c\u0438\u0440\u043e\u0432\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u043b\u0443\u0447\u0448\u0438\u0445 TypeScript-\u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p><strong>\u041f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443:<\/strong><\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/asouei\/safe-fetch\" rel=\"noopener noreferrer nofollow\">GitHub \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/asouei\/safe-fetch#readme\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.npmjs.com\/package\/@asouei\/safe-fetch\" rel=\"noopener noreferrer nofollow\">npm \u043f\u0430\u043a\u0435\u0442<\/a><\/p>\n<\/li>\n<\/ul>\n<p>P.S. \u0415\u0441\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 &#8212; \u0437\u0432\u0435\u0437\u0434\u0430 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0438 \u0432\u0430\u0448 \u0444\u0438\u0434\u0431\u0435\u043a \u0432 Issues \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0434\u0432\u0438\u0433\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/943732\/\"> https:\/\/habr.com\/ru\/articles\/943732\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"\">\n<div><figcaption>&#171;You can&#8217;t have errors in your code if you wrap the entire codebase in a try\/catch block&#187;<\/figcaption><\/div>\n<\/figure>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u043c \u0441\u043c\u0435\u0448\u043d\u043e\u0439, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0441\u043e\u0437\u043d\u0430\u0435\u0448\u044c, \u0447\u0442\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043c\u044b \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u043c. \u0422\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0435 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0441\u0440\u0430\u0437\u0443, \u0430 \u043a\u0430\u0436\u0434\u044b\u0439 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u041f\u0438\u0448\u0435\u0448\u044c <code>fetch<\/code> \u0438 \u0440\u0435\u0444\u043b\u0435\u043a\u0442\u043e\u0440\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0448\u044c <code>try\/catch<\/code>. \u0413\u0434\u0435-\u0442\u043e \u0441\u043b\u043e\u0432\u0438\u043b <code>TypeError<\/code>, \u0433\u0434\u0435-\u0442\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442, \u0433\u0434\u0435-\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u0435\u0440\u043d\u0443\u043b 500. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u043a\u043e\u0434\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0448\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 &#8212; \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<p>\u042f \u0433\u043e\u0434\u0430\u043c\u0438 \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u043b, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u043d\u044f\u043b: \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043d\u0435 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043b\u043e\u0432\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0438. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <code>fetch<\/code> \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0441 \u0438\u0445 \u043b\u043e\u0432\u0438\u0442\u044c \u0432\u0435\u0437\u0434\u0435 \u0438 \u0432\u0441\u0435\u0433\u0434\u0430.<\/p>\n<p>\u0422\u0430\u043a \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <strong><a class=\"mention\" href=\"\/users\/asouei\">@asouei<\/a>\/safe-fetch<\/strong>. \u0415\u0435 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0441\u0442\u0430: \u0443\u0431\u0440\u0430\u0442\u044c <code>try\/catch<\/code> \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430.<\/p>\n<h3>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0441\u0442\u0430\u043b\u0438 \u0432\u0441\u0435\u0445<\/h3>\n<p>\u041f\u043e\u043c\u043d\u0438\u0442\u0435 \u044d\u0442\u0443 \u043a\u0440\u0430\u0441\u043e\u0442\u0443?<\/p>\n<pre><code class=\"typescript\">try {   const res = await fetch('\/api\/users');   if (!res.ok) {     throw new Error(`HTTP ${res.status}: ${res.statusText}`);   }   const data = await res.json();   \/\/ \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0441 data } catch (e) {   \/\/ \u0430 \u0442\u0443\u0442 \u043b\u043e\u0432\u0438\u043c \u0432\u0441\u0435 \u043f\u043e\u0434\u0440\u044f\u0434: \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b, 404, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0441\u0435\u0442\u044c\u044e   console.error('\u0427\u0442\u043e-\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a:', e.message); } <\/code><\/pre>\n<figure class=\"\">\n<div><figcaption>\u041c\u0435\u043c \u043f\u0440\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a: exception \u0432 \u0432\u0438\u0434\u0435 \u043c\u0435\u0434\u0432\u0435\u0434\u044f, \u0430 try, catch \u0438 finally \u0443\u0431\u0435\u0433\u0430\u044e\u0442 \u043e\u0442 \u043d\u0435\u0433\u043e<\/figcaption><\/div>\n<\/figure>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043c\u0435\u0441\u044f\u0446 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a. \u0410 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435:<\/p>\n<ul>\n<li>\n<p><code>fetch<\/code> \u043a\u0438\u0434\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0441\u0431\u043e\u0438. 404 \u0438 500 \u043d\u0430\u0434\u043e \u043b\u043e\u0432\u0438\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0442 &#171;\u043e\u0431\u0449\u0435\u0433\u043e \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430&#187; \u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e. \u0422\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0441\u0442\u044b\u043b\u0438 \u0441 <code>AbortController<\/code><\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0433\u0438\u043a\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043e\u0432? \u041f\u0438\u0448\u0438 \u0441\u0430\u043c \u0438\u043b\u0438 \u0442\u0430\u0449\u0438 \u0442\u044f\u0436\u0435\u043b\u044b\u0439 axios<\/p>\n<\/li>\n<li>\n<p>\u041e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b. \u0412 TypeScript \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0433\u0430\u0434\u0430\u0442\u044c \u0447\u0442\u043e \u0432 <code>e.message<\/code><\/p>\n<\/li>\n<\/ul>\n<h3>\u0427\u0442\u043e \u044f \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c<\/h3>\n<p>\u0422\u0440\u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0432\u0435\u0449\u0438:<\/p>\n<p><strong>1. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 throw<\/strong><br \/> \u041a\u0430\u0436\u0434\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u0444\u043b\u0430\u0433\u043e\u043c <code>ok<\/code>.<\/p>\n<p><strong>2. \u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/strong><br \/> \u0412\u043c\u0435\u0441\u0442\u043e \u0437\u0430\u0433\u0430\u0434\u043e\u0447\u043d\u043e\u0433\u043e <code>e.message<\/code> &#8212; \u0447\u0435\u0442\u043a\u0438\u0435 \u0442\u0438\u043f\u044b: <code>NetworkError<\/code>, <code>TimeoutError<\/code>, <code>HttpError<\/code>, <code>ValidationError<\/code>.<\/p>\n<p><strong>3. \u0424\u0438\u0448\u043a\u0438 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438<\/strong><br \/> \u041e\u0431\u0449\u0438\u0439 \u0442\u0430\u0439\u043c\u0430\u0443\u0442, \u0443\u043c\u043d\u044b\u0435 \u0440\u0435\u0442\u0440\u0430\u0438, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 <code>Retry-After<\/code>.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442:<\/p>\n<pre><code class=\"typescript\">import { safeFetch } from '@asouei\/safe-fetch';  const result = await safeFetch.get&lt;{ users: User[] }&gt;('\/api\/users');  if (result.ok) {   console.log(result.data.users); } else {   console.error(result.error.name); \/\/ NetworkError | TimeoutError | ... } <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u0439: \u043b\u0438\u0431\u043e <code>{ ok: true, data }<\/code>, \u043b\u0438\u0431\u043e <code>{ ok: false, error }<\/code>.<br \/> \u041d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e <code>try\/catch<\/code> \u0432 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0435.<\/p>\n<h3>\u0427\u0442\u043e \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c<\/h3>\n<h4>\u0414\u0432\u043e\u0439\u043d\u044b\u0435 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b<\/h4>\n<p>\u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c <code>timeoutMs<\/code> \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0438 <code>totalTimeoutMs<\/code> \u0434\u043b\u044f \u0432\u0441\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"typescript\">const api = createSafeFetch({   timeoutMs: 5000,        \/\/ 5\u0441 \u043d\u0430 \u043f\u043e\u043f\u044b\u0442\u043a\u0443   totalTimeoutMs: 30000   \/\/ 30\u0441 \u0432\u0441\u0435\u0433\u043e (\u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0440\u0435\u0442\u0440\u0430\u0438) }); <\/code><\/pre>\n<h4>\u0423\u043c\u043d\u044b\u0435 \u0440\u0435\u0442\u0440\u0430\u0438<\/h4>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e <code>GET<\/code> \u0438 <code>HEAD<\/code> &#8212; \u044d\u0442\u043e \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432 POST-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432:<\/p>\n<pre><code class=\"typescript\">const result = await safeFetch.get('\/api\/flaky', {   retries: {     retries: 3,     baseDelayMs: 300  \/\/ \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 backoff   } }); <\/code><\/pre>\n<h4>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 Retry-After<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u0435\u0440\u043d\u0443\u043b 429 \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c &#8212; \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u0430\u043c\u0430 \u043f\u043e\u0434\u043e\u0436\u0434\u0435\u0442:<\/p>\n<pre><code class=\"typescript\">\/\/ \u0421\u0435\u0440\u0432\u0435\u0440: 429 Too Many Requests, Retry-After: 60 \/\/ safe-fetch: \u0436\u0434\u0435\u043c \u0440\u043e\u0432\u043d\u043e 60 \u0441\u0435\u043a\u0443\u043d\u0434 <\/code><\/pre>\n<h4>Validation \u0431\u0435\u0437 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/h4>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c Zod \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0445\u0435\u043c\u0443:<\/p>\n<pre><code class=\"typescript\">const result = await safeFetch.get('\/user\/123', {   validate: (data) =&gt; UserSchema.safeParse(data).success      ? { success: true, data }      : { success: false, error: 'Invalid user' } }); <\/code><\/pre>\n<h3>\u0420\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u043b\u044c\u0437\u0430<\/h3>\n<h4>\u0414\u043e: \u043a\u043e\u0434\u043e\u0432\u0430\u044f \u0431\u0430\u0437\u0430 \u0438\u0437 \u0430\u0434\u0430<\/h4>\n<pre><code class=\"typescript\">async function getUsers() {   try {     const res = await fetch('\/api\/users');     if (!res.ok) throw new Error(`${res.status}`);     return await res.json();   } catch (e) {     logger.error('Users fetch failed', e);     throw e; \/\/ \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435   } }  async function createUser(data) {   try {     const res = await fetch('\/api\/users', {       method: 'POST',       body: JSON.stringify(data)     });     if (!res.ok) throw new Error(`${res.status}`);     return await res.json();   } catch (e) {     logger.error('User creation failed', e);     throw e;   } } <\/code><\/pre>\n<h4>\u041f\u043e\u0441\u043b\u0435: \u0447\u0438\u0441\u0442\u044b\u0439 \u043a\u043e\u0434<\/h4>\n<pre><code class=\"typescript\">const api = createSafeFetch({   baseURL: '\/api',   interceptors: {     onError: (error) =&gt; logger.error('API error', error)   } });  async function getUsers() {   return api.get&lt;User[]&gt;('\/users'); }  async function createUser(data: NewUser) {   return api.post&lt;User&gt;('\/users', data); } <\/code><\/pre>\n<p>\u0412\u0435\u0441\u044c error handling \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0445\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a.<\/p>\n<h3>\u0418\u0441\u0442\u043e\u0440\u0438\u044f \u0438\u0437 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438<\/h3>\n<p>\u0423 \u043c\u0435\u043d\u044f \u0431\u044b\u043b \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435, \u0433\u0434\u0435 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u043c\u0438 API. \u041d\u0430 \u0431\u0443\u043c\u0430\u0433\u0435 \u0432\u0441\u0451 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u043f\u0440\u043e\u0441\u0442\u043e: \u0434\u0435\u0440\u0433\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435. \u041d\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u0441\u0451 \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u043b\u0430.<\/p>\n<p><strong>\u0427\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u0438\u0441 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u043b 500-\u043c\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u043b\u044e\u0431\u0438\u043b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043f\u0443\u0441\u0442\u044b\u0435 JSON-\u044b, \u0445\u043e\u0442\u044f \u0441\u0442\u0430\u0442\u0443\u0441 \u0431\u044b\u043b 200<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043e\u0442\u0432\u0435\u0442\u044b \u0437\u0430\u0432\u0438\u0441\u0430\u043b\u0438 \u043d\u0430 \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0441\u0435\u043a\u0443\u043d\u0434, \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0436\u0430\u043b\u043e\u0432\u0430\u043b\u0438\u0441\u044c, \u0447\u0442\u043e \u00ab\u043a\u043d\u043e\u043f\u043a\u0430 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u00bb<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043a\u043e\u0434 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043b\u0441\u044f \u0432 \u0445\u0430\u043e\u0441 \u0438\u0437 <code>try\/catch<\/code>, \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432 \u0441 <code>AbortController<\/code> \u0438 \u043a\u0443\u0447\u0438 \u043b\u043e\u0433\u043e\u0432 \u0432\u0440\u043e\u0434\u0435 \u00abRequest failed again\u00bb. \u041c\u044b \u0434\u0430\u0436\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u0438\u0434\u0435\u044e \u0442\u0430\u0449\u0438\u0442\u044c axios, \u0445\u043e\u0442\u044f \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0433\u043e\u0440\u0435\u043b \u0436\u0435\u043b\u0430\u043d\u0438\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u0442\u044f\u0436\u0435\u043b\u0443\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c.<\/p>\n<p>\u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u0441\u043e\u0431\u0440\u0430\u043b\u0441\u044f \u0438 \u0441\u043a\u0430\u0437\u0430\u043b: \u00ab\u0425\u0432\u0430\u0442\u0438\u0442. \u041c\u044b \u0442\u0440\u0430\u0442\u0438\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u043b\u043e\u0432\u043b\u044e \u043e\u0448\u0438\u0431\u043e\u043a, \u0447\u0435\u043c \u043d\u0430 \u0444\u0438\u0447\u0438\u00bb. \u0422\u0430\u043a \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f safe-fetch.<\/p>\n<p><strong>\u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0412\u0435\u0441\u044c error handling \u0443\u0435\u0445\u0430\u043b \u0432 interceptors &#8212; \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0433\u0434\u0435 \u0438\u0441\u043a\u0430\u0442\u044c \u0431\u0430\u0433\u0438<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0442\u0440\u0430\u0438 \u043d\u0430 GET \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0441\u043f\u0430\u0441\u043b\u0438 \u043e\u0442 \u0444\u043b\u0435\u0439\u043a\u0438 API (\u0440\u0430\u043d\u044c\u0448\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u0444\u0440\u0435\u0448\u0438\u043b\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443)<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0449\u0438\u0439 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u0438\u0437\u0431\u0430\u0432\u0438\u043b \u043e\u0442 \u00ab\u0432\u0435\u0447\u043d\u044b\u0445\u00bb \u0441\u043f\u0438\u043d\u043d\u0435\u0440\u043e\u0432, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0436\u0434\u0430\u043b \u043e\u0442\u0432\u0435\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u0440\u0438\u0434\u0451\u0442<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043b\u043e\u0433\u0430\u0445 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0432\u043d\u044f\u0442\u043d\u044b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a (<code>NetworkError<\/code>, <code>TimeoutError<\/code>), \u0430 \u043d\u0435 \u0437\u0430\u0433\u0430\u0434\u043e\u0447\u043d\u044b\u0435 \u00abundefined\u00bb<\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u043d\u0435\u0434\u0435\u043b\u044c \u043c\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 <strong>\u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043f\u0438\u0448\u0435\u043c try\/catch \u0432\u043e\u043a\u0440\u0443\u0433 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/strong>. \u0418 \u044d\u0442\u043e \u0441\u0442\u0430\u043b\u043e \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u0432\u0441\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<h3>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u0430\u043c\u0438<\/h3>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u0424\u0438\u0447\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">safe-fetch<\/p>\n<\/th>\n<th>\n<p align=\"left\">axios<\/p>\n<\/th>\n<th>\n<p align=\"left\">ky<\/p>\n<\/th>\n<th>\n<p align=\"left\">fetch<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0420\u0430\u0437\u043c\u0435\u0440<\/p>\n<\/td>\n<td>\n<p align=\"left\">~3kb<\/p>\n<\/td>\n<td>\n<p align=\"left\">~13kb<\/p>\n<\/td>\n<td>\n<p align=\"left\">~11kb<\/p>\n<\/td>\n<td>\n<p align=\"left\">0kb<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2705<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0422\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2705<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041e\u0431\u0449\u0438\u0439 \u0442\u0430\u0439\u043c\u0430\u0443\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2705<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Retry-After<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2705<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Zod-ready<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2705<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u274c<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043f\u0435\u0440\u0432\u044b\u0435 \u0448\u0430\u0433\u0438<\/h3>\n<pre><code class=\"bash\">npm install @asouei\/safe-fetch <\/code><\/pre>\n<p>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"typescript\">import { safeFetch } from '@asouei\/safe-fetch';  const users = await safeFetch.get&lt;User[]&gt;('\/api\/users'); if (users.ok) {   console.log(users.data); } else {   console.error(users.error.name, users.error.message); } <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"typescript\">import { createSafeFetch } from '@asouei\/safe-fetch';  const api = createSafeFetch({   baseURL: 'https:\/\/api.example.com',   headers: { 'Authorization': `Bearer ${token}` },   timeoutMs: 10000,   retries: { retries: 2 } }); <\/code><\/pre>\n<h3>\u0414\u043b\u044f \u043a\u043e\u0433\u043e \u044d\u0442\u043e<\/h3>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u044b, \u0443\u0441\u0442\u0430\u0432\u0448\u0438\u0435 \u043e\u0442 \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442\u044b \u0441 \u0436\u0435\u0441\u0442\u043a\u0438\u043c\u0438 SLA, \u0433\u0434\u0435 \u0432\u0430\u0436\u043d\u044b \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u044b \u0438 \u0440\u0435\u0442\u0440\u0430\u0438<\/p>\n<\/li>\n<li>\n<p>TypeScript-\u043a\u043e\u0434\u0431\u0430\u0437\u044b, \u0433\u0434\u0435 \u043d\u0443\u0436\u043d\u0430 \u0442\u043e\u0447\u043d\u0430\u044f \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u044f\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0443 fetch \u0441 production-\u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u044c\u044e<\/p>\n<\/li>\n<\/ul>\n<h3>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435<\/h3>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u0430 \u043a \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0443. \u0412 \u043f\u043b\u0430\u043d\u0430\u0445:<\/p>\n<ul>\n<li>\n<p>ESLint \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0434\u043b\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 <code>{ ok }<\/code><\/p>\n<\/li>\n<li>\n<p>\u0413\u043e\u0442\u043e\u0432\u044b\u0435 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u044b \u0434\u043b\u044f React Query \u0438 SWR<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u043b\u044f Next.js \u0438 Cloudflare Workers<\/p>\n<\/li>\n<\/ul>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435 \u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b \u044d\u0442\u0443 \u0448\u0442\u0443\u043a\u0443 \u0434\u043b\u044f \u0441\u0435\u0431\u044f, \u0447\u0442\u043e\u0431\u044b \u0441\u0430\u043c\u043e\u043c\u0443 \u0431\u044b\u043b\u043e \u043b\u0435\u0433\u0447\u0435. \u041d\u043e \u0432\u0441\u043a\u043e\u0440\u0435 \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 &#8212; \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p><strong>safe-fetch<\/strong> \u043d\u0435 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c axios \u0438\u043b\u0438 ky. \u041e\u043d\u0430 \u0440\u0435\u0448\u0430\u0435\u0442 \u043e\u0434\u043d\u0443 \u0437\u0430\u0434\u0430\u0447\u0443: \u0434\u0435\u043b\u0430\u0435\u0442 fetch \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u0439 &#8212; \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0431\u0438\u0440\u0430\u0435\u0442 \u0442\u0443 \u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u0443\u044e \u0431\u043e\u043b\u044c, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0432\u0441\u0435 \u0441\u043c\u0438\u0440\u0438\u043b\u0438\u0441\u044c.<\/p>\n<p>\u041c\u043e\u0436\u0435\u0442, \u0432\u044b \u0442\u043e\u0436\u0435 \u0443\u0441\u0442\u0430\u043b\u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c \u0434\u0436\u0443\u043d\u0430\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c <code>res.ok<\/code>? \u0418\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u043a\u0430\u0436\u0434\u043e\u043c API-\u043c\u0435\u0442\u043e\u0434\u0435? \u0415\u0441\u043b\u0438 \u0434\u0430 &#8212; \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0434\u0435\u043b\u044e \u0432\u044b \u0443\u0436\u0435 \u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0441\u0442\u0430\u0440\u044b\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c.<\/p>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0431\u0430\u0433\u0438 \u0438\u043b\u0438 \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0447\u0442\u043e-\u0442\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c &#8212; \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 Issues. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u044d\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u043e\u0434\u0438\u043b\u0430\u0441\u044c \u0438\u0437 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0438 \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u043d\u0430 \u0440\u0430\u0441\u0442\u0435\u0442 \u043e\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0438\u0434\u0431\u0435\u043a\u0430.<\/p>\n<ul>\n<li>\n<p>\ud83c\udf1f \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 <a href=\"https:\/\/github.com\/dzharii\/awesome-typescript\" rel=\"noopener noreferrer nofollow\">Awesome TypeScript<\/a> \u2014 \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u0440\u0443\u043f\u043d\u0435\u0439\u0448\u0438\u0445 \u043c\u0438\u0440\u043e\u0432\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u043b\u0443\u0447\u0448\u0438\u0445 TypeScript-\u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p><strong>\u041f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443:<\/strong><\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/asouei\/safe-fetch\" rel=\"noopener noreferrer nofollow\">GitHub \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/asouei\/safe-fetch#readme\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.npmjs.com\/package\/@asouei\/safe-fetch\" rel=\"noopener noreferrer nofollow\">npm \u043f\u0430\u043a\u0435\u0442<\/a><\/p>\n<\/li>\n<\/ul>\n<p>P.S. \u0415\u0441\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 &#8212; \u0437\u0432\u0435\u0437\u0434\u0430 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0438 \u0432\u0430\u0448 \u0444\u0438\u0434\u0431\u0435\u043a \u0432 Issues \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0434\u0432\u0438\u0433\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/943732\/\"> https:\/\/habr.com\/ru\/articles\/943732\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-473890","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/473890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=473890"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/473890\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=473890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=473890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=473890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}