Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/RecipeImageViewPager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export const RecipeImageViewPager = (props: Props) => {
props.onImageAdded?.(uuid);
}).catch((error) => {
// TODO: Error handling
console.error(error);
alert('Error uploading picture' + error);
console.error(error, JSON.stringify(error));
alert('Error uploading picture' + JSON.stringify(error));
});
};

Expand Down
11 changes: 6 additions & 5 deletions src/dao/RestAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class RestAPI {
}


const response = await this.post('/recipes-images', formData);
const response = await this.post('/recipes-images', formData, {'Content-Type': 'multipart/form-data'});
return response?.data.uuid;
}
static async getRecipeById(recipeId: number): Promise<Recipe> {
Expand All @@ -345,9 +345,10 @@ class RestAPI {
});
}

static async axiosConfig(): Promise<AxiosRequestConfig> {
static async axiosConfig(headers?: {[headerName: string]: string}): Promise<AxiosRequestConfig> {
const mergedHeaders = {...await this.getAuthHeader(), ...headers};
return {
headers: await this.getAuthHeader(),
headers: mergedHeaders,
};
}

Expand Down Expand Up @@ -401,9 +402,9 @@ class RestAPI {
return await AppPersistence.getBackendURL() + AppPersistence.getApiRoute() + path;
}

private static async post(apiPath: string, data: any) {
private static async post(apiPath: string, data: any, headers?: {[headerName: string]: string}) {
try {
return await axios.post(await this.url(apiPath), data, await this.axiosConfig());
return await axios.post(await this.url(apiPath), data, await this.axiosConfig(headers));
} catch (e) {
await RestAPI.handleAxiosError(e);
// Retry after error handling
Expand Down