2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Typescriptで Expected error to be handled エラー

Posted at

環境

MacOS Big Sur 11.7
Nuxt.js 2.15.7

問題

下記のコードで  Expected error to be handled というエラーが出た。 

  await axios
    .get('/api/user')
    .then(async (response) => {
      if (response.status === 200) {
        user = response.data
      }
    })
    .catch((error: any) => {
      return null
    })
  return user

とりあえずの解決方法

.catch の中をかく(今回はconsoleにerrorを返す)

  await axios
    .get('/api/user')
    .then(async (response) => {
      if (response.status === 200) {
        user = response.data
      }
    })
    .catch((error: any) => {
      console.log(error)
      return null
    })
  return user
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?