Skip to content

Commit

Permalink
Merge pull request #4103 from traPtitech/fix/register_error_message
Browse files Browse the repository at this point in the history
ユーザー登録のエラーメッセージをいい感じに
  • Loading branch information
mehm8128 committed Oct 23, 2023
2 parents ac51266 + a616c44 commit b15f57e
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/components/Authenticate/composables/useRegister.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import apis from '/@/lib/apis'
import type { AxiosError } from 'axios'

const useRegister = () => {
const router = useRouter()
Expand All @@ -17,7 +18,33 @@ const useRegister = () => {

router.push('/')
} catch (e) {
error.value = '' + e
const err = e as AxiosError<{ message: string }>
if (!err.response) return

const message = err.response.data.message
const status = err.response.status
switch (true) {
case message.includes('name: cannot be blank.'):
error.value = 'IDを入力してください'
break
case message.includes('password: cannot be blank.'):
error.value = 'パスワードを入力してください'
break
case message.includes('name conflicts'):
error.value = 'そのIDは既に使用されています'
break
case message.includes(
'password: the length must be between 10 and 32.'
):
error.value = 'パスワードは10~32字で入力してください'
break
case message.includes('name: must contain [a-zA-Z0-9_-] only.'):
error.value =
'IDは半角英数字とハイフン、アンダースコアのみ使用できます'
break
default:
error.value = `${status}: ${message}`
}
}
}

Expand Down

0 comments on commit b15f57e

Please sign in to comment.