Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
erp5
Commits
c98f5f0a
Commit
c98f5f0a
authored
Oct 12, 2023
by
Titouan Soulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_api_style: fix Unauthorized exception to avoid redirect
parent
abeaee60
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
bt5/erp5_api_style/DocumentTemplateItem/portal_components/document.erp5.jIOWebSection.py
...lateItem/portal_components/document.erp5.jIOWebSection.py
+19
-4
No files found.
bt5/erp5_api_style/DocumentTemplateItem/portal_components/document.erp5.jIOWebSection.py
View file @
c98f5f0a
...
@@ -33,10 +33,26 @@ from Acquisition import aq_inner
...
@@ -33,10 +33,26 @@ from Acquisition import aq_inner
from
OFS.Traversable
import
NotFound
from
OFS.Traversable
import
NotFound
from
erp5.component.document.WebSection
import
WebSection
from
erp5.component.document.WebSection
import
WebSection
from
Products.ERP5Type
import
Permissions
from
Products.ERP5Type
import
Permissions
from
zExceptions
import
HTTPClientError
from
zLOG
import
LOG
,
INFO
from
zLOG
import
LOG
,
INFO
MARKER
=
[]
MARKER
=
[]
# Redefine an Unauthorized error to avoid Zope redirecting the user to the main ERP5 login form
class
jIOUnauthorized
(
HTTPClientError
):
errmsg
=
'Unauthorized'
status
=
401
def
__init__
(
self
,
underlyingError
):
HTTPClientError
.
__init__
(
self
)
self
.
underlyingError
=
underlyingError
def
__str__
(
self
):
return
str
(
self
.
underlyingError
)
def
__bytes__
(
self
):
return
bytes
(
self
.
underlyingError
)
def
convertTojIOAPICall
(
function
):
def
convertTojIOAPICall
(
function
):
"""
"""
Wrap the method to create a log entry for each invocation to the zope logger
Wrap the method to create a log entry for each invocation to the zope logger
...
@@ -45,19 +61,18 @@ def convertTojIOAPICall(function):
...
@@ -45,19 +61,18 @@ def convertTojIOAPICall(function):
"""
"""
Log the call, and the result of the call
Log the call, and the result of the call
"""
"""
#assert(self.REQUEST.REQUEST_METHOD == "POST")
try
:
try
:
self
.
REQUEST
.
response
.
setHeader
(
"Content-Type"
,
"application/json"
)
self
.
REQUEST
.
response
.
setHeader
(
"Content-Type"
,
"application/json"
)
retval
=
function
(
self
,
*
args
,
**
kwd
)
retval
=
function
(
self
,
*
args
,
**
kwd
)
except
Unauthorized
,
e
:
except
Unauthorized
,
e
:
LOG
(
'jIOWebSection'
,
INFO
,
'Converting Unauthorized to Unauthorized error mesage in JSON,'
,
error
=
True
)
body
=
self
.
ERP5Site_logApiErrorAndReturn
(
body
=
self
.
ERP5Site_logApiErrorAndReturn
(
error_code
=
"40
3
"
,
error_code
=
"40
1
"
,
error_message
=
str
(
e
),
error_message
=
str
(
e
),
error_name
=
"Unauthorized"
error_name
=
"Unauthorized"
)
)
self
.
REQUEST
.
response
.
setBody
(
body
,
lock
=
True
)
self
.
REQUEST
.
response
.
setBody
(
body
,
lock
=
True
)
raise
raise
jIOUnauthorized
(
e
)
except
NotFound
,
e
:
except
NotFound
,
e
:
LOG
(
'jIOWebSection'
,
INFO
,
'Converting NotFound to NotFound error mesage in JSON,'
,
LOG
(
'jIOWebSection'
,
INFO
,
'Converting NotFound to NotFound error mesage in JSON,'
,
error
=
True
)
error
=
True
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment