<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>int128</author_name>
  <author_url>https://blog.hatena.ne.jp/int128/</author_url>
  <blog_title>GeekFactory</blog_title>
  <blog_url>https://int128.hatenablog.com/</blog_url>
  <categories>
    <anon>spring</anon>
  </categories>
  <description>Spring BootのREST APIサーバで例外発生時のエラー情報をJSONで返す方法を調べたのでメモです。 やりたいこと 例外が発生した場合は常にエラー情報をJSONで返したい。 例外の種類によってステータスコードを分けたい。例えば、バリデーションエラーが発生した場合は400、その他は500を返す。 Spring MVCの本来の振る舞いは変更しない。例えば、認可エラーで401を返す振る舞いは維持する。 実現方法 ErrorController インタフェースを実装すると、例外時のレスポンスをカスタマイズできる。 キャッチした例外によってステータスコードを変更する。 ステータスコードを指定…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fint128.hatenablog.com%2Fentry%2F2016%2F11%2F27%2F230529&quot; title=&quot;Spring Bootで例外発生時にJSONを返す - GeekFactory&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url>https://images-fe.ssl-images-amazon.com/images/I/51MBlgJ0pTL._SL160_.jpg</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2016-11-27 23:05:29</published>
  <title>Spring Bootで例外発生時にJSONを返す</title>
  <type>rich</type>
  <url>https://int128.hatenablog.com/entry/2016/11/27/230529</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
