Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
7301 มุมมอง

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 

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

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

check it now for a code sample

ผู้เขียน

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

ผู้เขียน

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

ผู้เขียน

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ค. 25
372
2
ก.ค. 25
723
1
มิ.ย. 25
2248
1
มิ.ย. 25
651
Controller not working แก้ไขแล้ว
2
มิ.ย. 25
578