As you already mention that anyone with the knowledge of developer console can tweak the DOM you can also read about it here Preventing users to enter into developers tools and therefore you should not give the APIs to the user which are irrelevant.
If you still want a solution, then this will hugely depend upon the use case but you can use EJS if you're using Express and restrict the rendering of a particular block of HTML!
You can also apply some server side logic to preprocess the request and depending upon that you can give a proper response whichever necessary.
For example if a user is not authenticated to request a recourse, from the server you can have a server side logic for there authentication and response with a 401 status with a message that you're not authorized to do this action.