---
# System prepended metadata

title: Adding Error Handler and Refactoring Code base

---

# Adding Error Handler and Refactoring Code base
```javascript=
export const errorHandler = (error) => {
    var message = { code: '', message: '' }

    switch (error) {
        case 4061:
            message.code = error
            message.message = 'E-mail already exist.'
            break
        case 4041:
            message.code = error
            message.message = 'Not a valid email address.'
            break
        default:
            // message.code = error.code
            // message.message = error.detail
            if (validator.equals(error.code + '', '23505')) {
                message.code = error.code
                message.message = error.detail
            } else {
                message.code = error.code
                message.message = error
            }
            break
    }

    return message

}

```