Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Override web.http.JsonRequest for custom error handling v7.0

By
Mayte
on 12/7/15, 12:38 PM 406 views

Hello:

How can I implement my own custom error handling? I need to remove the traceback when user is not in debug mode and instead display a more end-user friendly msg, in spanish.
I can't locate the web.main method to inherit. I tried inheriting web.http.JsonRequest dispatch() method but did not work.


Thanks
Mayte 

0

Axel Mendoza

--Axel Mendoza--
10228
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 12/7/15, 11:39 PM

Hi Mayte

Could you post what you tried with JsonRequest class to try it? normally this get solved by doing a monkey patch on addons/web/http.py

Like:

from openerp.addons.web import session,http
 
class JsonRequest(http.WebRequest):
    def dispatch(self, method):
        ....my changes to error response here...

#monkey patching
http.JsonRequest = JsonRequest

0
Mayte
On 12/8/15, 10:40 AM

Hi Axel:
As you say, I did it by doing a patch directly on web/http.py, but sinces modifying core addons is not a recommended practice I want to inherit in my own addon.

I tried:
Created addons\my_addon\httpy.py as follows:

from web import session 
from web.http import WebRequest
from web.http import JsonRequest

class JsonRequest(WebRequest):
    def dispatch(self, method):
        ....my changes to error response here...
I added httpy.py to my init.py and even tryed adding dependance to web on my __openerp__.py, but still native error msg in english with traceback is being displayed!

Thanks!

Mayte
PD:My Karma doesn't allow me to delete my first response

Seems that your code is not get called, you are not monkey patching the JsonRequest, let me put an example of how I do this kind of things in an answer update

Axel Mendoza
on 12/11/15, 11:17 PM

check it now for a code sample

Axel Mendoza
on 12/11/15, 11:21 PM

Hi Axel: I was missing the actual monkey patch. It worked like charm!...thanks.

Mayte
on 12/15/15, 4:33 PM

However, now my code is being called even if my custom addon is uninstalled!!

Mayte
on 12/15/15, 5:10 PM

Hi: Does monkey patches get call all the time when the original addon is installed?, is there a way to install/uninstalled the addon that does the monkey patch? Thanks Mayte

Mayte
on 1/5/16, 12:57 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/7/15, 12:38 PM
Seen: 406 times
Last updated: 12/8/15, 10:40 AM