tested and fixed
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
			
		||||
import log from "../utils/log";
 | 
			
		||||
import customError from "./customError";
 | 
			
		||||
import responses from './responseCodes';
 | 
			
		||||
import log from "../utils/log.js";
 | 
			
		||||
import customError from "./customError.js";
 | 
			
		||||
import responses from './responseCodes.js';
 | 
			
		||||
import translate from '../utils/translate.js';
 | 
			
		||||
 | 
			
		||||
const errorHandler = (err, req, res) => {
 | 
			
		||||
@@ -9,7 +9,7 @@ const errorHandler = (err, req, res) => {
 | 
			
		||||
    let language = req.headers["accept-language"];
 | 
			
		||||
 | 
			
		||||
    if (err instanceof customError) {
 | 
			
		||||
        return res.status(responses.getHTTPCode(err.code)).send(translate(language, code));
 | 
			
		||||
        return res.status(responses.getHTTPCode(err.code)).send(translate(language, err.code));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,3 @@
 | 
			
		||||
import fs from 'fs';
 | 
			
		||||
 | 
			
		||||
const responses = {
 | 
			
		||||
    authentication: {
 | 
			
		||||
        not_found: "authentication not found",
 | 
			
		||||
@@ -8,7 +6,8 @@ const responses = {
 | 
			
		||||
    user: {
 | 
			
		||||
        duplicate: "user duplicate",
 | 
			
		||||
        invalid_syntax: "user invalid syntax",
 | 
			
		||||
        already_in_group: "user already in group"
 | 
			
		||||
        already_in_group: "user already in group",
 | 
			
		||||
        not_found: "user not found"
 | 
			
		||||
    },
 | 
			
		||||
    usernames: {
 | 
			
		||||
        duplicate: "username taken",
 | 
			
		||||
@@ -28,8 +27,6 @@ const responses = {
 | 
			
		||||
    },
 | 
			
		||||
    abstractproducts: {
 | 
			
		||||
        not_found: "abstract product not found",
 | 
			
		||||
        hash_without_file: "hash without file",
 | 
			
		||||
        file_without_hash: "file without hash",
 | 
			
		||||
        invalid_syntax: "abstract product invalid syntax"
 | 
			
		||||
    },
 | 
			
		||||
    barcode: {
 | 
			
		||||
@@ -95,7 +92,7 @@ const responses = {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const getHTTPCode = (type) => {
 | 
			
		||||
    switch (code) {
 | 
			
		||||
    switch (type) {
 | 
			
		||||
        case responses.general.ok:
 | 
			
		||||
            return 200
 | 
			
		||||
        case responses.general.invalid_syntax:
 | 
			
		||||
@@ -118,6 +115,8 @@ const getHTTPCode = (type) => {
 | 
			
		||||
            return 409
 | 
			
		||||
        case responses.user.invalid_syntax:
 | 
			
		||||
            return 400
 | 
			
		||||
        case responses.user.not_found:
 | 
			
		||||
            return 404
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        case responses.usernames.duplicate:
 | 
			
		||||
@@ -145,10 +144,6 @@ const getHTTPCode = (type) => {
 | 
			
		||||
 | 
			
		||||
        case responses.abstractproducts.not_found:
 | 
			
		||||
            return 404
 | 
			
		||||
        case responses.abstractproducts.file_without_hash:
 | 
			
		||||
            return 400
 | 
			
		||||
        case responses.abstractproducts.hash_without_file:
 | 
			
		||||
            return 400
 | 
			
		||||
        case responses.abstractproducts.invalid_syntax:
 | 
			
		||||
            return 400
 | 
			
		||||
 | 
			
		||||
@@ -166,15 +161,6 @@ const getHTTPCode = (type) => {
 | 
			
		||||
        case responses.abstractproductname.too_long:
 | 
			
		||||
            return 400
 | 
			
		||||
 | 
			
		||||
        case responses.abstractproducts.file_without_hash:
 | 
			
		||||
            return 400
 | 
			
		||||
        case responses.abstractproducts.hash_without_file:
 | 
			
		||||
            return 400
 | 
			
		||||
        case responses.abstractproducts.invalid_syntax:
 | 
			
		||||
            return 400
 | 
			
		||||
        case responses.abstractproducts.not_found:
 | 
			
		||||
            return 404
 | 
			
		||||
 | 
			
		||||
        case responses.amount.invalid_syntax:
 | 
			
		||||
            return 400
 | 
			
		||||
        case responses.amount.too_long:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user