kritsana135-hooray-server
Version:
for server
20 lines (18 loc) • 755 B
JavaScript
import { ApolloError } from 'apollo-server';
import { EN } from '../constants/language';
export default function ErrorMessage(locale = EN, error) {
// == Example ==
// {
// message: {
// en: "Error not found",
// th: "ไม่พบข้อผิดพลาด",
// },
// code: "ERROR_NOT_FOUND",
// }
if (!error.message) throw new ApolloError('Error message: Message not found', 400);
if (!error.message[locale]) locale = EN;
if (!error.message[locale]) throw new ApolloError('Error message: Language not found', 400);
if (!error.code) throw new ApolloError('Error message: Code not found', 400);
console.log(`\n== ${error.message[locale]} ==\n`);
throw new ApolloError(error.message[locale], error.code);
}