]> zoso.dev Git - nano-pow.git/commitdiff
Default to a more generic error message if action is unknown.
authorChris Duncan <chris@zoso.dev>
Fri, 18 Apr 2025 20:48:56 +0000 (13:48 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 18 Apr 2025 20:48:56 +0000 (13:48 -0700)
src/bin/server.ts

index 8c411955de14d0f9cbbc9a281035074263dededa..b208d222428e0b2bc92d0f6e7e8a230f8be62fd5 100755 (executable)
@@ -80,7 +80,7 @@ process.on('SIGHUP', async (): Promise<void> => {
 async function respond (res: http.ServerResponse, data: Buffer[]): Promise<void> {
        let statusCode: number = 500
        let headers: http.OutgoingHttpHeaders = { 'Content-Type': 'application/json' }
-       let response: string = 'work_validate failed'
+       let response: string = 'request failed'
        try {
                const datastring = Buffer.concat(data).toString().replace(/\s+/g, '')
                if (Buffer.byteLength(datastring) > MAX_BODY_SIZE) {
@@ -90,6 +90,7 @@ async function respond (res: http.ServerResponse, data: Buffer[]): Promise<void>
                if (action !== 'work_generate' && action !== 'work_validate') {
                        throw new Error('Invalid action. Must be work_generate or work_validate.')
                }
+               response = `${action} failed`
                if (!/^[0-9A-Fa-f]{64}$/.test(hash ?? '')) {
                        throw new Error('Invalid hash. Must be a 64-character hex string.')
                }
@@ -99,7 +100,6 @@ async function respond (res: http.ServerResponse, data: Buffer[]): Promise<void>
                if (action === 'work_validate' && !/^[0-9A-Fa-f]{16}$/.test(work ?? '')) {
                        throw new Error('Invalid work. Must be a 16-character hex string.')
                }
-               response = `${action} failed`
                const options: NanoPowOptions = {
                        debug: CONFIG.DEBUG,
                        effort: CONFIG.EFFORT,