Return "Resource does not exist" error if requesting a non-existent resource via GET_QDN_RESOURCE_URL.

This commit is contained in:
CalDescent 2023-04-21 19:50:01 +01:00
parent b1ebe1864b
commit db4a9ee880
2 changed files with 19 additions and 3 deletions

View File

@ -653,6 +653,7 @@ let res = await qortalRequest({
```
### Get URL to load a QDN resource
Note: this returns a "Resource does not exist" error if a non-existent resource is requested.
```
let url = await qortalRequest({
action: "GET_QDN_RESOURCE_URL",
@ -664,6 +665,7 @@ let url = await qortalRequest({
```
### Get URL to load a QDN website
Note: this returns a "Resource does not exist" error if a non-existent resource is requested.
```
let url = await qortalRequest({
action: "GET_QDN_RESOURCE_URL",
@ -673,6 +675,7 @@ let url = await qortalRequest({
```
### Get URL to load a specific file from a QDN website
Note: this returns a "Resource does not exist" error if a non-existent resource is requested.
```
let url = await qortalRequest({
action: "GET_QDN_RESOURCE_URL",

View File

@ -46,6 +46,18 @@ function handleResponse(event, response) {
responseObj = response;
}
// GET_QDN_RESOURCE_URL has custom handling
const data = event.data;
if (data.action == "GET_QDN_RESOURCE_URL") {
if (responseObj == null || responseObj.status == null || responseObj.status == "NOT_PUBLISHED") {
responseObj = {};
responseObj.error = "Resource does not exist";
}
else {
responseObj = buildResourceUrl(data.service, data.name, data.identifier, data.path, false);
}
}
// Respond to app
if (responseObj.error != null) {
event.ports[0].postMessage({
@ -173,9 +185,10 @@ window.addEventListener("message", (event) => {
return httpGetAsyncWithEvent(event, "/names/" + data.name);
case "GET_QDN_RESOURCE_URL":
const response = buildResourceUrl(data.service, data.name, data.identifier, data.path, false);
handleResponse(event, response);
return;
// Check status first; URL is built ant returned automatically after status check
url = "/arbitrary/resource/status/" + data.service + "/" + data.name;
if (data.identifier != null) url = url.concat("/" + data.identifier);
return httpGetAsyncWithEvent(event, url);
case "LINK_TO_QDN_RESOURCE":
if (data.service == null) data.service = "WEBSITE"; // Default to WEBSITE