diff --git a/ui/mock-server.js b/ui/mock-server.js index a82cbb4..3b8e19b 100644 --- a/ui/mock-server.js +++ b/ui/mock-server.js @@ -4,7 +4,15 @@ const express = require('express') const app = express() const port = 3000 +let showError = false + function progressSimulation (res) { + if (showError) { + var resp = JSON.stringify({ Error: 'Simulated error.' }) + '\n' + res.write(resp) + res.status(200).end() + return + } var progress = 0.0 var timer = setInterval(() => { var resp = JSON.stringify({ Status: ['Processing...', progress] }) + '\n' @@ -18,6 +26,10 @@ function progressSimulation (res) { } function returnConfig (res) { + if (showError) { + res.status(500).json({}) + return + } res.json({ installing_message: 'Test Banner Bold 
Code block
 Italic Strike', @@ -52,6 +64,7 @@ function returnConfig (res) { } app.get('/api/attrs', (req, res) => { + console.log('-- Get attrs') res.send( { name: 'yuzu', target_url: 'https://raw.githubusercontent.com/j-selby/test-installer/master/config.linux.v2.toml' } ) @@ -88,8 +101,18 @@ app.post('/api/start-install', (req, res) => { app.get('/api/exit', (req, res) => { console.log('-- Exit') + if (showError) { + res.status(500).send('Simulated error: Nothing to see here.') + return + } res.status(204) }) +app.get('/api/mock_error', (req, res) => { + console.log('-- Toggle error emulation') + showError = !showError + res.status(200).send(`Error emulation: ${showError}\n`) +}) + console.log(`Listening on ${port}...`) app.listen(port)