![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/vreg/node_modules/@nuxtjs/youch/examples/ |
'use strict' const http = require('http') const Youch = require('../src/Youch') class HttpException extends Error { constructor (...args) { super(...args) this.name = this.constructor.name } } function foo () { const error = new HttpException('Some weird error') error.status = 503 throw error } http.createServer((req, res) => { let youch = null try { foo() } catch (e) { youch = new Youch(e, req) } youch .toHTML() .then((response) => { res.writeHead(200, {'content-type': 'text/html'}) res.write(response) res.end() }).catch((error) => { res.writeHead(500) res.write(error.message) res.end() }) }).listen(8000, () => { console.log('listening to port 8000') })