Skip to content

Commit

Permalink
Fixed error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
FaultierSP committed Aug 30, 2024
1 parent 466521e commit a9a590e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "civitaiapiclient",
"version": "0.0.4"
"version": "0.0.5"
},
"tauri": {
"allowlist": {
Expand Down
11 changes: 7 additions & 4 deletions src/components/Images.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,30 +204,33 @@ const Images = (props) => {
}
}

console.log(api_config);
console.log(data);

fetch('https://civitai.com'+api_prefix+'images',{
method:'GET',
query:data,
responseType:ResponseType.JSON,
headers:api_config
})
.then((response) => {
if (response.data.items.length==0) {
props.showErrorMessage("No images found.");
return;
}

if (response.data.metadata.nextPage) {
setLoadMoreAPIURL(response.data.metadata.nextPage);
setLoadMoreButtonDisabled(false);
}
else {
setLoadMoreButtonDisabled(true);
}

setImagesTableData(response.data.items);
setDownloadButtonDisabled(true);
//setSelectedRowKeys([]);
})
.catch((error) => {
if(typeof error!=undefined) {
props.showErrorMessage(error.response.data.error);
//props.showErrorMessage(error);
}
})
.finally(()=>{
Expand Down
27 changes: 23 additions & 4 deletions src/components/SearchCreatorsOfImages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const SearchCreatorsOfImages = (props) => {
};

function getFirstBatchOfImages() {
//console.clear();

setAwaitingAPIResponse(true);
setResultVisible(false);

Expand All @@ -43,6 +41,27 @@ const SearchCreatorsOfImages = (props) => {
headers: api_config,
})
.then((response) => {
if(response.status !== 200) {
if (typeof response.data.error === 'object') {
let error_message = "";

Object.entries(response.data.error.issues).forEach(([key, value]) => {
error_message += value.message + "\n";
});

setResultTitle(error_message);
} else {
setResultTitle(response.data.error);
}

setResultSubTitle(null);
setResultStatus("warning");
setResultButtons(null);
setResultVisible(true);

return;
}

if(response.data.items.length == 0 ) {
setResultTitle("Couldn't find any images by this creator.");
setResultSubTitle(null);
Expand Down Expand Up @@ -72,12 +91,12 @@ const SearchCreatorsOfImages = (props) => {
.catch((error) => {
setResultTitle(error.message);

if(error.response.data.error) {
/*if(error.response && error.response.data && error.response.data.error) {
setResultSubTitle(error.response.data.error);
}
else {
setResultSubTitle(null);
}
}*/

setResultStatus("error");
setResultButtons(null);
Expand Down

0 comments on commit a9a590e

Please sign in to comment.