{"id":172,"date":"2015-06-01T22:46:24","date_gmt":"2015-06-01T17:46:24","guid":{"rendered":"http:\/\/developer.uz\/blog\/?p=172"},"modified":"2015-06-01T22:49:11","modified_gmt":"2015-06-01T17:49:11","slug":"httpexception-in-yii2","status":"publish","type":"post","link":"https:\/\/developer.uz\/blog\/httpexception-in-yii2\/","title":{"rendered":"\u0412\u0438\u0434\u044b HttpException \u0432 Yii2"},"content":{"rendered":"<p>\u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u043e\u0442\u0432\u0435\u0442\u0435 Http-\u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043a\u0438\u0439 3-\u0445 \u0437\u043d\u0430\u0447\u043d\u044b\u0439 \u043a\u043e\u0434. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0442\u0440\u0430\u043a\u0442\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0414\u0443\u043c\u0430\u044e \u0432\u0441\u0435\u043c \u0432\u0435\u0431-\u043c\u0430\u0441\u0442\u0435\u0440\u0430\u043c \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043a\u043e\u0434 &#171;404 &#8212; Not found&#187;. \u041a\u043e\u0434\u043e\u0432 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432\u0441\u0435 \u043e\u043d\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 Http \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430. \u041d\u043e \u0437\u043d\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 Exception (\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f) \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0433\u0440\u0443\u043f\u043f\u0443 \u043a\u043e\u0434\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u0430. \u0413\u0440\u0443\u043f\u043f \u0432\u0441\u0435\u0433\u043e 5:<\/p>\n<ul>\n<li>1xx \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f<\/li>\n<li>2xx \u0423\u0441\u043f\u0435\u0448\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/li>\n<li>3xx \u041f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f (\u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442)<\/li>\n<li> 4xx \u041e\u0448\u0438\u0431\u043a\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/li>\n<li> 5xx \u041e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435<\/li>\n<\/ul>\n<p>\u041a \u043e\u0448\u0438\u0431\u043a\u0430\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435, \u043a \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435, \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0432\u044b\u0437\u043e\u0432 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<br \/>\n\u041a \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u043c \u043e\u0448\u0438\u0431\u043a\u0430\u043c \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430.<br \/>\n\u0418\u0437 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u0448\u0435\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0443\u0436\u043d\u044b \u043a\u043e\u0434\u044b \u0438\u0437 4 \u0433\u0440\u0443\u043f\u043f\u044b. <\/p>\n<h2>HttpException \u0432 Yii2<\/h2>\n<p>\u0417\u0430\u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0443\u0436\u043d\u044b Exception? \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432 \u0441\u043b\u0443\u0447\u0430\u0438 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0433\u043b\u043e \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0430 \u043f\u043e \u0442\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435. Exception \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 try catch.<br \/>\n\u0412 Yii2 \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \\yii\\web\\HttpException \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. <\/p>\n<pre class=\"brush: php; title: \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434; notranslate\" title=\"\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434\">\r\n throw new HttpException(404 ,'User not found');\r\n<\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u043e \u0437\u0432\u0443\u0447\u043d\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u0434\u043b\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043e\u0448\u0438\u0431\u043e\u043a, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u043a\u043e\u0434 \u043e\u0442\u0432\u0435\u0442\u0430. <\/p>\n<ul>\n<li>BadRequestHttpException &#8212; 400 \u043e\u0448\u0438\u0431\u043a\u0430<\/li>\n<li>UnauthorizedHttpException &#8212; 401 \u043e\u0448\u0438\u0431\u043a\u0430<\/li>\n<li>ForbiddenHttpException &#8212; 403 \u043e\u0448\u0438\u0431\u043a\u0430<\/li>\n<li>NotFoundHttpException &#8212; 404 \u043e\u0448\u0438\u0431\u043a\u0430<\/li>\n<li>MethodNotAllowedHttpException &#8212; 405 \u043e\u0448\u0438\u0431\u043a\u0430<\/li>\n<li>NotAcceptableHttpException &#8212; 406 \u043e\u0448\u0438\u0431\u043a\u0430<\/li>\n<li>ConflictHttpException &#8212; 409 \u043e\u0448\u0438\u0431\u043a\u0430<\/li>\n<li>GoneHttpException &#8212; 410 \u043e\u0448\u0438\u0431\u043a\u0430<\/li>\n<li>UnsupportedMediaTypeHttpException &#8212; 415 \u043e\u0448\u0438\u0431\u043a\u0430<\/li>\n<li>TooManyRequestsHttpException &#8212; 429 \u043e\u0448\u0438\u0431\u043a\u0430<\/li>\n<li>ServerErrorHttpException &#8212; 500 \u043e\u0448\u0438\u0431\u043a\u0430<\/li>\n<\/ul>\n<p>\u0412\u0441\u0435 \u043e\u043d\u0438 \u043e\u0442\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u044b \u043e\u0442 \\yii\\web\\HttpException \u0438 \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u044e\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0438 \u043a\u043e\u0434\u0430 \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<pre class=\"brush: php; title: \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434; notranslate\" title=\"\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434\">\r\n throw new NotFoundHttpException('User not found');\r\n<\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u043e\u0442\u0432\u0435\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 setStatusCode() \u043a\u043b\u0430\u0441\u0441\u0430 yii\\web\\Response<\/p>\n<pre class=\"brush: php; title: \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434; notranslate\" title=\"\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434\">\r\nYii::$app-&gt;response-&gt;setStatusCode(422);\r\n<\/pre>\n<p>\u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0447\u0442\u043e-\u043b\u0438\u0431\u043e \u0432 \u0442\u0435\u043b\u0435 \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u043e\u0442\u0432\u0435\u0442\u0435 Http-\u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043a\u0438\u0439 3-\u0445 \u0437\u043d\u0430\u0447\u043d\u044b\u0439 \u043a\u043e\u0434. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0442\u0440\u0430\u043a\u0442\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0414\u0443\u043c\u0430\u044e \u0432\u0441\u0435\u043c \u0432\u0435\u0431-\u043c\u0430\u0441\u0442\u0435\u0440\u0430\u043c \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043a\u043e\u0434 &#171;404 &#8212; Not found&#187;. \u041a\u043e\u0434\u043e\u0432 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432\u0441\u0435 \u043e\u043d\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 Http \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430. \u041d\u043e \u0437\u043d\u0430\u0442\u044c \u0432\u0441\u0435 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 Exception (\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f) \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u0433\u0440\u0443\u043f\u043f\u0443 \u043a\u043e\u0434\u043e\u0432 \u043e\u0442\u0432\u0435\u0442\u0430. \u0413\u0440\u0443\u043f\u043f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[13],"_links":{"self":[{"href":"https:\/\/developer.uz\/blog\/wp-json\/wp\/v2\/posts\/172"}],"collection":[{"href":"https:\/\/developer.uz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.uz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.uz\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.uz\/blog\/wp-json\/wp\/v2\/comments?post=172"}],"version-history":[{"count":7,"href":"https:\/\/developer.uz\/blog\/wp-json\/wp\/v2\/posts\/172\/revisions"}],"predecessor-version":[{"id":179,"href":"https:\/\/developer.uz\/blog\/wp-json\/wp\/v2\/posts\/172\/revisions\/179"}],"wp:attachment":[{"href":"https:\/\/developer.uz\/blog\/wp-json\/wp\/v2\/media?parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.uz\/blog\/wp-json\/wp\/v2\/categories?post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.uz\/blog\/wp-json\/wp\/v2\/tags?post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}