Tuesday, 1 September 2020

http-proxy-middleware econnreset error after successful post request

Developing a contact form using Nodejs/Express and create-react-app following this tutorial https://www.youtube.com/watch?v=o3eR0X91Ogs. The issue that I'm running into is that when I hit submit on the form the message succeeds, and I get it in my inbox. However, in the developer console, I am hit with the timeout error I set on the axios.post located in Contact.js, and in my terminal it logs message sent, console log located in index.js, immediately throwing the following error afterward:

HPM ERROR: Error: socket hang up
[1]     at connResetException (internal/errors.js:612:14)
[1]     at Socket.socketCloseListener (_http_client.js:443:25)
[1]     at Socket.emit (events.js:326:22)
[1]     at TCP.<anonymous> (net.js:673:12) {
[1]   code: 'ECONNRESET'
[1] }
[1] [HPM] Error occurred while trying to proxy request /api/contact/ from localhost:3001 to http://localhost:3000/ (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)

Does anyone know why this error is occurring, and how I can fix it? The message sends but hangs afterward which prevents the app state from resetting (resetForm). At the same time, the axios.post in Contact.js doesn't update the state of sent to true.

The Github repo for the project.

Edit: I've been stuck on this for a few days now. Looked at similar questions, attempted ALL the fixes I could find, and this error still persists.



from http-proxy-middleware econnreset error after successful post request

Stay SOLID and DRY with coroutines and functions as methods in python

I have that Code example:

from time import sleep
import asyncio

class bird:

    def __init__(self, sleeptime=1):
        self.var = sleeptime

    def wait_meep(self):
        sleep(self.var)
        print("Meep")

    def do_sth(self):
        print("Dop Dop Do do ...")


class bird_async:

    def __init__(self, sleeptime=1):
        self.var = sleeptime

    async def wait_meep(self):
        await asyncio.sleep(self.var)
        print("Meep")

    def do_sth(self):
        print("Dop Dop Do do ...")

As you can see, both clients are mostly identical and shall contain the same name (so that everyone knows what to expect). Now I want to be DRY and write bird_async(bird). Because every extension in bird shall be used in bird_async as well. This is possible, but my coworker says, it is not SOLID, because I have overwritten wait_meep. Now I am looking for different soultions and found abstract classes. What I don't know is, if creating an abstract class birdBase(ABC) would be SOLID as well. I would overwrite there as well, because first it was a function and then a couroutine, or am I wrong here?

What could be a SOLID and DRY solution to get those both classes together, without renaming the methods?



from Stay SOLID and DRY with coroutines and functions as methods in python

Firebase functions throws uncatchable error

I'm calling the following Firebase function:

exports.getUserRecord = functions.https.onCall(async (data, context) => {
    try {
        //This successfully logs an existing uid in firestore, it should be retrievable
        console.log(context.auth.uid)

        const doc = admin.firestore().collection('user').doc(context.auth.uid);
        const res = await doc.get() //Isolated it down to this line that is failing
        return res
    } catch (err) {
        console.log(err)
        throw new functions.https.HttpsError('unavailable', 'some error message');
    }
});

When calling this function I receive the following error on the client:

POST https://us-central1-xxx-xxx.cloudfunctions.net/getUserRecord 500
Uncaught (in promise) Error: INTERNAL

On the server logs I see this error:

Unhandled error function error(...args) {
    write(entryFromArgs('ERROR', args));
} 

I am wondering how there is an error that neither of my error logging lines are picking up, and also what is causing this error?

EDIT: I have also tried logging other things within my catch block but they do not appear, it seems there is an error but the code does not enter the catch block somehow.

I have also seen this post which seems to suggest this was an issue that was patched in firebase-functions 3.9.1, but I have upgraded and still have this issue



from Firebase functions throws uncatchable error