You may be able to find a quirky way to set the HTTP response header, but you then probably be able to distinguish request coming from your controller and requests coming for elsewhere in Umbraco.
The getById method doesn't let you specify your own configuration, so you won't be able do it this way either - at least not directly:
But you could copy the implementation of the getById function:
function (id) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"contentApiBaseUrl",
"GetById",
{ id: id })),
'Failed to retrieve data for content id ' + id)
.then(function (result) {
return $q.when(umbDataFormatter.formatContentGetData(result));
});
}
into:
function getById(id, config) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"contentApiBaseUrl",
"GetById",
{ id: id }), config),
'Failed to retrieve data for content id ' + id)
.then(function (result) {
return $q.when(umbDataFormatter.formatContentGetData(result));
});
}
Remember to inject the different parts via DI.
When using your own getById function, you can then call it like getById(1234, { umbIgnoreErrors: true }).
I haven't tested this code just now, but I'd reckon it should work 😉
Thanks for your help. I was just revisiting the problem and re-found your post which I was so sure that I had marked as solution.
In the end my troubles were also related to
umbRequestHelper.resourcePromise( $http.get(umbRequestHelper.getApiUrl('mediaApiBaseUrl', 'GetById', [{ id: id }])), 'Failed to retrieve data for media id ' + id);
which luckily also accepts the same parameter { umbIgnoreErrors: true }
umbRequestHelper.resourcePromise( $http.get(umbRequestHelper.getApiUrl('mediaApiBaseUrl', 'GetById', [{ id: id }]), { umbIgnoreErrors: true }), 'Failed to retrieve data for media id ' + id);
contentResource.getById warns when accessing
If you call this method with an id that you dont have access to - then you are prompted with a red alert warning in Umbraco backend.
When it fails we are thrown into a catch block and deals with it.
Can the UI red alert warning be avoided somehow? Any undocumented parameters?
Hi Jesper,
Umbraco listen for either a HTTP header or in the configuration object for the request to the API:
https://github.com/umbraco/Umbraco-CMS/blob/34e80d86e8c0b754f6b7a02e307f53cb32806bbe/src/Umbraco.Web.UI.Client/src/common/interceptors/security.interceptor.js#L47
You may be able to find a quirky way to set the HTTP response header, but you then probably be able to distinguish request coming from your controller and requests coming for elsewhere in Umbraco.
The
getById
method doesn't let you specify your own configuration, so you won't be able do it this way either - at least not directly:But you could copy the implementation of the
getById
function:https://github.com/umbraco/Umbraco-CMS/blob/34e80d86e8c0b754f6b7a02e307f53cb32806bbe/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js#L372
This means turning something like:
into:
Remember to inject the different parts via DI.
When using your own
getById
function, you can then call it likegetById(1234, { umbIgnoreErrors: true })
.I haven't tested this code just now, but I'd reckon it should work 😉
Hi Anders,
Thanks for your help. I was just revisiting the problem and re-found your post which I was so sure that I had marked as solution.
In the end my troubles were also related to
which luckily also accepts the same parameter
{ umbIgnoreErrors: true }
It solved my problem.
Thanks
Jesper
is working on a reply...