Skip to content

Commit

Permalink
fix: set logs for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
georgimld committed Nov 13, 2024
1 parent 5d6902f commit 24afa74
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/utils/requests/innoUsers/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const logger = getLogger();

export async function createInnoUser(body: Omit<UserSession, 'image'>, image?: string | null) {
try {
logger.debug('Image URL: ' + image);
const uploadedImages = image ? await uploadImage(image, `avatar-${body.name}`) : null;
const uploadedImage = uploadedImages ? uploadedImages[0] : null;
const response = await strapiGraphQLFetcher(CreateInnoUserMutation, {
Expand Down Expand Up @@ -69,7 +70,14 @@ export async function createInnoUserIfNotExist(body: Omit<UserSession, 'image'>,

async function uploadImage(imageUrl: string, fileName: string) {
return fetch(imageUrl)
.then((response) => response.blob())
.catch((e) => {
logger.error('Error while fetching image:', e);
throw new Error('Error while fetching image');
})
.then((response) => {
logger.debug(response.status);
return response.blob();
})
.then(async function (myBlob) {
const formData = new FormData();
formData.append('files', myBlob, fileName);
Expand All @@ -83,8 +91,13 @@ async function uploadImage(imageUrl: string, fileName: string) {
},
body: formData,
})
.catch((e) => {
logger.error('Error while uploading image:', e);
throw new Error('Error while uploading image');
})
.then((response) => response.json())
.then((result) => {
logger.debug('Image uploading result: ' + JSON.stringify(result[0]));
return result;
});
});
Expand Down

0 comments on commit 24afa74

Please sign in to comment.