Add error handling for closed and draft surveys; update related interfaces

This commit is contained in:
Dimas Wiese
2026-03-16 01:15:13 +01:00
parent 81f88f10f8
commit 129af44641
4 changed files with 20 additions and 7 deletions

View File

@@ -249,7 +249,7 @@ export class ParticipatePage implements OnInit, OnDestroy {
}
private friendlyError(
reason: 'invalid_token' | 'already_submitted' | 'survey_not_found'
reason: 'invalid_token' | 'already_submitted' | 'survey_not_found' | 'survey_closed' | 'survey_draft'
): string {
switch (reason) {
case 'invalid_token':
@@ -258,6 +258,10 @@ export class ParticipatePage implements OnInit, OnDestroy {
return 'You have already submitted a response for this survey. Each link can only be used once.';
case 'survey_not_found':
return 'The survey could not be found on the host. It may have been deleted.';
case 'survey_draft':
return 'This survey is not yet open for responses. Please try again later.';
case 'survey_closed':
return 'This survey is closed and no longer accepting responses.';
}
}
}

View File

@@ -85,7 +85,8 @@
</ion-item>
<div class="ion-margin-top button-row">
<ion-button *ngIf="!isHosting" expand="block" (click)="startHosting()">
<ion-button *ngIf="!isHosting" expand="block" (click)="startHosting()"
[disabled]="survey.status !== 'active'">
<ion-icon slot="start" name="play-outline"></ion-icon>
Start Hosting
</ion-button>

View File

@@ -12,7 +12,7 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ToastController, AlertController, Platform } from '@ionic/angular';
import { ToastController } from '@ionic/angular';
import { DataConnection } from 'peerjs';
import { Subscription } from 'rxjs';
import { SurveyService } from '../../services/survey.service';
@@ -52,9 +52,7 @@ export class SurveyDetailPage implements OnInit, OnDestroy {
private surveyService: SurveyService,
private responseService: ResponseService,
private peerService: PeerService,
private toastCtrl: ToastController,
private alertCtrl: AlertController,
private platform: Platform
private toastCtrl: ToastController
) {}
async ngOnInit(): Promise<void> {
@@ -228,6 +226,16 @@ export class SurveyDetailPage implements OnInit, OnDestroy {
if (!this.survey) return;
if (msg.type === 'join') {
if (this.survey.status === 'draft') {
conn.send({ type: 'error', reason: 'survey_draft' } as P2PMessage);
return;
}
if (this.survey.status === 'closed') {
conn.send({ type: 'error', reason: 'survey_closed' } as P2PMessage);
return;
}
const participant = await this.surveyService.getParticipant(msg.token);
if (!participant || participant.surveyId !== this.surveyId) {

View File

@@ -134,4 +134,4 @@ export type P2PMessage =
/** Host acknowledges a successful submit or update */
| { type: 'ack'; status: 'submitted' | 'updated' }
/** Host signals an error — participant should display the reason */
| { type: 'error'; reason: 'invalid_token' | 'already_submitted' | 'survey_not_found' };
| { type: 'error'; reason: 'invalid_token' | 'already_submitted' | 'survey_not_found' | 'survey_closed' | 'survey_draft' };