forked from noxious/server
Added titles to error notifications
This commit is contained in:
parent
4992ef69d4
commit
f0c0456121
@ -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).' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user