use Flarum\Core\Exception\ValidationException;
throw new ValidationException([
'someattribute' => 'I\'m afraid I can\'t let you do that Dave.',
]);
If you're inside a modal and catch API errors and bind them to onerror
(via js), then the error will appear in the modal itself:
app.session.user.save({
someattribute: 'test',
}).then(() => {
// do something when done
}).catch(this.onerror.bind(this));