Constant in back-end not accessible by front-end

I have a dictionary in a web-module in my back-end that contains some Error types that I want to use:

export const Errors = {
    ItemNotFoundError: Error("Item not found error"),
    DatabaseError: Error("Database error"),
};

I have a function to get an item in another back-end web-module that uses these errors; it returns a promise that rejects when the item can’t be found:

reject(Errors.ItemNotFoundError)

So in the front end I should be able to just import Errors and check the error that the promise returns against the predefined errors I have created. This would be a nice single source of truth for my error messages.

The problem I’m having is that after the error is successfully sent to the front end I am not able to access the dictionary in the Errors web-module back-end file. I am importing and using it the same way that I did when created my get item function in the back-end. Any ideas what might be going wrong here?

You are keeping your front end logic in a separate file, yes? So before you set up your routes, you need to invoke express in a variable called “app”, like so:
const app = express();
Now you can use “app.get()”, with the same arguments. Now to send your data to the front end, you need to paste the request to yelp into the callback of the .get function. Inside the .then function of your yelp request is where you take the json response, and send it to the client with:
res.json(response.jsonBody.businesses)
I hope that helps.

fb video downloader

@chelseafaza896 I appreciate the answer but I don’t think it is really what I was looking for. I figured out (by reading the docs) that you can only export functions from a web module, so I instead created a public .js file that contains error messages and used these to construct Error objects and check them against each other

@tim.bikedatabase Would you consider sharing your solution? I am interested in how you did this. I was thinking about using a custom table to hold that information, but then thought about overhead / performance possibly being impactful.

Thanks!