1

Is there a way to hide odoo error traceback for security reason ?

Note : using Odoo 15

example of traceback : enter image description here

Omar Tougui
  • 183
  • 2
  • 8

2 Answers2

2

You can extend the ErrorDialogBody template to show those details for admin users

Example:

<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

    <t t-inherit="web.ErrorDialogBody" t-inherit-mode="extension" owl="1">
        <xpath expr="//div/div" position="attributes">
            <attribute name="t-if">isAdmin</attribute>
        </xpath>
        <xpath expr="//div[hasclass('alert-warning')]/p[2]" position="attributes">
            <attribute name="t-if">isAdmin</attribute>
        </xpath>
        <xpath expr="//div[hasclass('alert-warning')]/p[2]" position="after">
            <p t-if="!isAdmin">Please contact the administrator.</p>
        </xpath>
        <xpath expr="//button[hasclass('btn-link')]" position="attributes">
            <attribute name="t-if">isAdmin</attribute>
        </xpath>
    </t>
    
</templates>

You need to patch the ErrorDialog to define the isAdmin variable

/** @odoo-module */

import { ErrorDialog } from "@web/core/errors/error_dialogs";
import { useService } from "@web/core/utils/hooks";
import { patch } from "@web/core/utils/patch";

patch(ErrorDialog.prototype, "ErrorDialog patch", {
    setup() {
        this._super(...arguments);
        this.isAdmin = useService("user").isAdmin;
    }
});
Kenly
  • 24,317
  • 7
  • 44
  • 60
  • Thanks for your reponse, I also found that I could hide the traceback using `sys.tracebacklimit = 0`. I will post it as another way to solve this. – Omar Tougui Mar 28 '23 at 12:21
  • In this case, the system admin will not see the error traceback – Kenly Mar 28 '23 at 12:47
0

Here is another way to hide the traceback in odoo 15 using python sys library :

import sys
sys.tracebacklimit = 0

I added this code to odoo/http.py

Omar Tougui
  • 183
  • 2
  • 8