add handle errors
MODIFY
package-lock.json
package-lock.json
"@types/node": "*"
}
},
+ "@types/busboy": {
+ "version": "0.2.3",
+ "resolved": "https://registry.npmjs.org/@types/busboy/-/busboy-0.2.3.tgz",
+ "integrity": "sha1-ZpetKYcyRsUw8Jo/9aQIYYJCMNU=",
+ "dev": true,
+ "requires": {
+ "@types/node": "*"
+ }
+ },
"@types/cfenv": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@types/cfenv/-/cfenv-1.2.0.tgz",
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.10.tgz",
"integrity": "sha512-C7srjHiVG3Ey1nR6d511dtDkCEjxuN9W1HWAEjGq8kpcwmNM6JJkpC0xvabM7BXTG2wDq8Eu33iH9aQKa7IvLQ=="
},
+ "@types/csvtojson": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/@types/csvtojson/-/csvtojson-1.1.5.tgz",
+ "integrity": "sha512-REZcfXN1h2JLoSc066GAdUKP2OpNiG3mIpgyjZWB5RKhBOZc5xmAZwavbP6O7vKMZ+jYTqbwUNucMBl7dw68JA==",
+ "dev": true,
+ "requires": {
+ "@types/node": "*"
+ }
+ },
"@types/debug": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz",
"integrity": "sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==",
"dev": true
},
+ "@types/jsonstream": {
+ "version": "0.8.30",
+ "resolved": "https://registry.npmjs.org/@types/jsonstream/-/jsonstream-0.8.30.tgz",
+ "integrity": "sha512-KqHs2eAapKL7ZKUiKI/giUYPVgkoDXkVGFehk3goo+3Q8qwxVVRC3iwg+hK/THORbcri4RRxTtlm3JoSY1KZLQ==",
+ "dev": true,
+ "requires": {
+ "@types/node": "*"
+ }
+ },
"@types/jsonwebtoken": {
"version": "8.5.0",
"resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-8.5.0.tgz",

MODIFY
package.json
package.json
"@types/bluebird-global": "^3.5.12",
"@types/body-parser": "^1.19.0",
"@types/body-parser-xml": "^1.1.0",
+ "@types/busboy": "^0.2.3",
"@types/cfenv": "^1.2.0",
"@types/chai": "^4.2.15",
"@types/chai-datetime": "0.0.36",
"@types/chai-subset": "^1.3.3",
"@types/convict": "^5.2.2",
"@types/cors": "^2.8.10",
+ "@types/csvtojson": "^1.1.5",
"@types/ejs": "^3.0.5",
"@types/express": "^4.17.11",
"@types/faker": "^5.1.6",
"@types/hpp": "^0.2.1",
"@types/i18n-js": "^3.8.0",
"@types/intl": "^1.2.0",
+ "@types/jsonstream": "^0.8.30",
"@types/jsonwebtoken": "^8.5.0",
"@types/lodash": "^4.14.168",
"@types/mocha": "^8.2.0",

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
import { Action, Entity } from '../../../../types/Authorization';
import { HTTPAuthError, HTTPError } from '../../../../types/HTTPError';
-import { NextFunction, Request, Response, json } from 'express';
+import { NextFunction, Request, Response } from 'express';
import { OCPITokenType, OCPITokenWhitelist } from '../../../../types/ocpi/OCPIToken';
import User, { UserStatus } from '../../../../types/User';
@@ -842,16 +842,36 @@ export default class UserService {
delimiter: ['\t'],
quote: 'off'
});
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
- converter.subscribe(async function(user) {
+ converter.subscribe(async (user) => {
await UserService.importUser(action, req, user);
+ }, (error) => {
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.INVALID_FILE_FORMAT,
+ message: 'Invalid csv file',
+ module: MODULE_NAME, method: 'handleUploadUsersFile',
+ user: req.user,
+ action: action,
+ detailedMessages: { error: error.message, stack: error.stack }
+ });
});
file.pipe(converter);
} else if (mimetype === 'application/json') {
const parser = JSONStream.parse('users.*');
- parser.on('data', async function(user) {
+ parser.on('data', async (user) => {
await UserService.importUser(action, req, user);
});
+ parser.on('error', function(error) {
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.INVALID_FILE_FORMAT,
+ message: 'Invalid json file',
+ module: MODULE_NAME, method: 'handleUploadUsersFile',
+ user: req.user,
+ action: action,
+ detailedMessages: { error: error.message, stack: error.stack }
+ });
+ });
file.pipe(parser);
} else {
throw new AppError({

add @types/ handle errors