Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ユーザー登録のエラーメッセージをいい感じに #4103

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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