1
0
forked from noxious/server

Added titles to error notifications

This commit is contained in:
Dennis Postma 2025-02-06 21:21:01 +01:00
parent 4992ef69d4
commit f0c0456121
2 changed files with 7 additions and 7 deletions

View File

@ -24,20 +24,20 @@ export default class CharacterCreateEvent extends BaseEvent {
const user = await userRepository.getById(this.socket.userId!)
if (!user) {
return this.socket.emit('notification', { message: 'User not found' })
return this.socket.emit('notification', { title: 'Error', message: 'You are not logged in' })
}
// Check if character name already exists
const characterExists = await characterRepository.getByName(data.name)
if (characterExists) {
return this.socket.emit('notification', { message: 'Character name already exists' })
return this.socket.emit('notification', { title: 'Error', message: 'Character name already exists' })
}
let characters: Character[] = await characterRepository.getByUserId(user.getId())
if (characters.length >= 4) {
return this.socket.emit('notification', { message: 'You can only have 4 characters' })
return this.socket.emit('notification', { title: 'Error', message: 'You can only create 4 characters' })
}
// @TODO: Change to default location
@ -47,7 +47,7 @@ export default class CharacterCreateEvent extends BaseEvent {
await newCharacter.setName(data.name).setUser(user).setMap(map!).save()
if (!newCharacter) {
return this.socket.emit('notification', { message: 'Failed to create character. Please try again (later).' })
return this.socket.emit('notification', { title: 'Error', message: 'Failed to create character. Please try again (later).' })
}
characters = [...characters, newCharacter]
@ -59,9 +59,9 @@ export default class CharacterCreateEvent extends BaseEvent {
} catch (error: any) {
this.logger.error(`character:create error: ${error.message}`)
if (error instanceof ZodError) {
return this.socket.emit('notification', { message: error.issues[0].message })
return this.socket.emit('notification', { title: 'Error', message: error.issues[0].message })
}
return this.socket.emit('notification', { message: 'Could not create character. Please try again (later).' })
return this.socket.emit('notification', { title: 'Error', message: 'Could not create character. Please try again (later).' })
}
}
}

View File

@ -131,7 +131,7 @@ export default class CharacterMove extends BaseEvent {
positionX: mapCharacter.character.positionX,
positionY: mapCharacter.character.positionY,
rotation: mapCharacter.character.rotation,
isMoving: false
isMoving: mapCharacter.isMoving
})
}
}