| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | import { __ } from '@wordpress/i18n' |
| 2 | 2 | import { isAxiosError } from 'axios' |
| 3 | 3 | import React, { useCallback } from 'react' |
| 4 | +import { describeRequestError } from '../utils/errors' | |
| 4 | 5 | import { useSnippetForm } from '../components/EditMenu/SnippetForm/WithSnippetFormContext' |
| 5 | 6 | import { createSnippetObject, isCondition } from '../utils/snippets/snippets' |
| 6 | 7 | import { buildUrl } from '../utils/urls' |
| 7 | 8 | import { useSnippetsAPI } from './useSnippetsAPI' |
| @@ -112,10 +113,10 @@ | ||
| 112 | 113 | ? api.create(request) |
| 113 | 114 | : api.update({ ...request, id })) |
| 114 | 115 | |
| 115 | 116 | return response.id ? createSnippetObject(response) : undefined |
| 116 | - } catch (error) { | |
| 117 | - return isAxiosError(error) ? error.message : undefined | |
| 117 | + } catch (error: unknown) { | |
| 118 | + return isAxiosError(error) ? describeRequestError(error) : undefined | |
| 118 | 119 | } finally { |
| 119 | 120 | setIsWorking(false) |
| 120 | 121 | } |
| 121 | 122 | })() |