Skip to content

Commit 5e51d27

Browse files
committed
Fixing of error processing
1 parent 00bab57 commit 5e51d27

File tree

7 files changed

+39
-14
lines changed

7 files changed

+39
-14
lines changed

.eslintrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ parserOptions:
1111

1212
rules:
1313
no-param-reassign: 0
14+
no-console: 0

src/js/RSSparse.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import ValidationRSSError from './ValidationRSSError';
2+
13
const getFeed = (dom) => {
24
const titleFeed = dom.querySelector('channel>title').textContent;
35
const descriptionFeed = dom.querySelector('channel>description').textContent;
@@ -25,7 +27,7 @@ const parseRSS = (data) => {
2527
};
2628
const parser = new DOMParser();
2729
const responseDom = parser.parseFromString(data, 'text/xml');
28-
if (responseDom.querySelector('parsererror')) throw new Error('invalid_RSS');
30+
if (responseDom.querySelector('parsererror')) throw new ValidationRSSError('invalid_RSS');
2931
newData.feed = getFeed(responseDom);
3032
newData.posts = getPosts(responseDom);
3133
return newData;

src/js/ValidationRSSError.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class ValidationRSSError extends Error {
2+
constructor(message) {
3+
super(message);
4+
this.name = 'ValidationRSSError';
5+
}
6+
}
7+
8+
export default ValidationRSSError;

src/js/app.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ const app = () => {
111111
watcherState.validationUrl.state = 'updated';
112112
const formData = new FormData(e.target);
113113
const existingURLs = watcherState.content.feeds.map((feed) => feed.url);
114-
validate(existingURLs, formData.get('url'))
114+
const currentURL = formData.get('url');
115+
validate(existingURLs, currentURL)
115116
.then((newUrl) => getAxiosResponse(newUrl))
116117
.then((response) => {
117118
const data = parseRSS(response.data.contents);
118-
const { url } = response.data.status;
119119
const feedId = Number(uniqueId());
120-
data.feed.url = url;
120+
data.feed.url = currentURL;
121121
data.feed.feedId = feedId;
122122
data.posts = data.posts.map((post) => ({
123123
...post,
@@ -130,12 +130,21 @@ const app = () => {
130130
updateFeeds(watcherState);
131131
})
132132
.catch((err) => {
133-
if (err.message === 'URL_invalid' || err.message === 'invalid_RSS') {
134-
watcherState.validationUrl.error = err.message;
135-
watcherState.validationUrl.state = 'invalid';
136-
} else {
137-
console.log('Выпала неизвесная ошибка:');
138-
console.dir(err);
133+
switch (err.name) {
134+
case 'ValidationError':
135+
case 'ValidationRSSError':
136+
watcherState.validationUrl.error = err.message;
137+
watcherState.validationUrl.state = 'invalid';
138+
break;
139+
case 'AxiosError':
140+
watcherState.validationUrl.error = err.code;
141+
watcherState.validationUrl.state = 'invalid';
142+
break;
143+
144+
default:
145+
console.log('Выпала неизвесная ошибка:');
146+
console.dir(err);
147+
break;
139148
}
140149
});
141150
});

src/js/locales/en.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export default {
77
title_feeds: 'Feeds',
88
posts: 'Posts',
99
button_in_post: 'Show',
10+
ERR_NETWORK: 'Network error',
1011
},
1112
};

src/js/locales/ru.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ export default {
33
URL_invalid: 'Ссылка должна быть валидным URL',
44
existing_RSS: 'RSS уже существует',
55
RSS_uploaded: 'RSS успешно загружен',
6-
invalid_RSS: 'Не содержит валидный RSS',
6+
invalid_RSS: 'Ресурс не содержит валидный RSS',
77
title_feeds: 'Фиды',
88
posts: 'Посты',
99
button_in_post: 'Просмотр',
10+
ERR_NETWORK: 'Ошибка сети',
1011
},
1112
};

webpack.config.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
55
const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
66
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
77
const autoprefixer = require('autoprefixer');
8-
const miniCssExtractPlugin = require('mini-css-extract-plugin');
8+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
99

10-
const isProduction = process.env.NODE_ENV == 'production';
10+
const isProduction = process.env.NODE_ENV === 'production';
1111

1212
const config = {
1313
target: 'web',
@@ -23,6 +23,9 @@ const config = {
2323
host: 'localhost',
2424
hot: true,
2525
},
26+
watchOptions: {
27+
poll: true,
28+
},
2629
plugins: [
2730
new HtmlWebpackPlugin({
2831
template: './index.html',
@@ -43,7 +46,7 @@ const config = {
4346
use: [
4447
{
4548
// Extracts CSS for each JS file that includes CSS
46-
loader: miniCssExtractPlugin.loader,
49+
loader: MiniCssExtractPlugin.loader,
4750
},
4851
{
4952
// Interprets `@import` and `url()` like `import/require()` and will resolve them

0 commit comments

Comments
 (0)