mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-22 00:38:03 -06:00
Client: fix error display for component
This commit is contained in:
parent
de59c48f5f
commit
bf68dd752d
@ -20,7 +20,7 @@ export class UserService {
|
||||
|
||||
return this.authHttp.post(UserService.BASE_USERS_URL, body)
|
||||
.map(this.restExtractor.extractDataBool)
|
||||
.catch((res) => this.restExtractor.handleError(res));
|
||||
.catch(this.restExtractor.handleError);
|
||||
}
|
||||
|
||||
getUsers() {
|
||||
|
@ -31,7 +31,7 @@ export class UserAddComponent implements OnInit {
|
||||
this.userService.addUser(this.username, this.password).subscribe(
|
||||
ok => this.router.navigate([ '/admin/users/list' ]),
|
||||
|
||||
err => this.error = err
|
||||
err => this.error = err.text
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ export class UserListComponent implements OnInit {
|
||||
this.totalUsers = totalUsers;
|
||||
},
|
||||
|
||||
err => alert(err)
|
||||
err => alert(err.text)
|
||||
);
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ export class UserListComponent implements OnInit {
|
||||
this.userService.removeUser(user).subscribe(
|
||||
() => this.getUsers(),
|
||||
|
||||
err => alert(err)
|
||||
err => alert(err.text)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -34,13 +34,19 @@ export class RestExtractor {
|
||||
handleError(res: Response) {
|
||||
let text = 'Server error: ';
|
||||
text += res.text();
|
||||
let json = res.json();
|
||||
let json = '';
|
||||
|
||||
try {
|
||||
json = res.json();
|
||||
} catch (err) { ; }
|
||||
|
||||
const error = {
|
||||
json,
|
||||
text
|
||||
};
|
||||
|
||||
console.error(error);
|
||||
|
||||
return Observable.throw(error);
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ export class VideoListComponent implements OnInit, OnDestroy {
|
||||
|
||||
this.loading.next(false);
|
||||
},
|
||||
error => alert(error)
|
||||
error => alert(error.text)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||
this.video = video;
|
||||
this.loadVideo();
|
||||
},
|
||||
error => alert(error)
|
||||
error => alert(error.text)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -69,14 +69,8 @@
|
||||
"src/app/shared/form-validators/url.validator.ts",
|
||||
"src/app/shared/index.ts",
|
||||
"src/app/shared/rest/index.ts",
|
||||
"src/app/shared/rest/mock-rest-table.ts",
|
||||
"src/app/shared/rest/rest-extractor.service.ts",
|
||||
"src/app/shared/rest/rest-filter.model.ts",
|
||||
"src/app/shared/rest/rest-pagination.ts",
|
||||
"src/app/shared/rest/rest-sort.ts",
|
||||
"src/app/shared/rest/rest-table-page.ts",
|
||||
"src/app/shared/rest/rest-table.spec.ts",
|
||||
"src/app/shared/rest/rest-table.ts",
|
||||
"src/app/shared/rest/rest.service.ts",
|
||||
"src/app/shared/search/index.ts",
|
||||
"src/app/shared/search/search-field.type.ts",
|
||||
@ -89,7 +83,6 @@
|
||||
"src/app/videos/shared/index.ts",
|
||||
"src/app/videos/shared/loader/index.ts",
|
||||
"src/app/videos/shared/loader/loader.component.ts",
|
||||
"src/app/videos/shared/pagination.model.ts",
|
||||
"src/app/videos/shared/sort-field.type.ts",
|
||||
"src/app/videos/shared/video.model.ts",
|
||||
"src/app/videos/shared/video.service.ts",
|
||||
|
@ -17,11 +17,20 @@ function usersAdd (req, res, next) {
|
||||
req.checkBody('username', 'Should have a valid username').isUserUsernameValid()
|
||||
req.checkBody('password', 'Should have a valid password').isUserPasswordValid()
|
||||
|
||||
// TODO: check we don't have already the same username
|
||||
|
||||
logger.debug('Checking usersAdd parameters', { parameters: req.body })
|
||||
|
||||
checkErrors(req, res, next)
|
||||
checkErrors(req, res, function () {
|
||||
User.loadByUsername(req.body.username, function (err, user) {
|
||||
if (err) {
|
||||
logger.error('Error in usersAdd request validator.', { error: err })
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
|
||||
if (user) return res.status(409).send('User already exists.')
|
||||
|
||||
next()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function usersRemove (req, res, next) {
|
||||
|
@ -590,6 +590,17 @@ describe('Test parameters validator', function () {
|
||||
requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204)
|
||||
})
|
||||
|
||||
it('Should fail if we add a user with the same username', function (done) {
|
||||
it('Should succeed with the correct params', function (done) {
|
||||
const data = {
|
||||
username: 'user1',
|
||||
password: 'my super password'
|
||||
}
|
||||
|
||||
requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409)
|
||||
})
|
||||
})
|
||||
|
||||
it('Should fail with a non admin user', function (done) {
|
||||
server.user = {
|
||||
username: 'user1',
|
||||
|
Loading…
Reference in New Issue
Block a user