• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DaniSomoza / galactic-commander / 7141953215

08 Dec 2023 01:28PM UTC coverage: 91.579%. First build
7141953215

push

github

web-flow
Add Auth microservice (#1)

* Add activationCode and sendEmail

* Added prettier and linter

* added tests

* add test action

1 of 2 branches covered (0.0%)

Branch coverage included in aggregate %.

85 of 92 new or added lines in 14 files covered. (92.39%)

86 of 93 relevant lines covered (92.47%)

1.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/packages/auth-microservice/src/errors/handleErrorResponse.ts
1
import { MongoServerError } from 'mongodb'
1✔
2
import StatusCodes from 'http-status-codes'
1✔
3
import Joi from 'joi'
1✔
4

5
import { bodyErrorResponse } from '../errors/AuthError'
6

7
const { BAD_REQUEST, CONFLICT, INTERNAL_SERVER_ERROR } = StatusCodes
1✔
8

9
type ErrorResponse = {
10
  code: number
11
  body: bodyErrorResponse
12
}
13

14
function handleErrorResponse(error: unknown): ErrorResponse {
15
  // TODO: improve Error handler!
16

17
  // idea: crear una clase AuthError que actua Mappeador de estos errores a algo unificado
18

19
  if (error instanceof Joi.ValidationError) {
2!
NEW
20
    return {
×
21
      code: BAD_REQUEST,
22
      body: {
23
        error: error.message,
24
        details: error.details
25
      }
26
    }
27
  }
28

29
  if (error instanceof MongoServerError) {
2✔
30
    // handle duplicated key error.code === 11000 || error.code === 11001
31
    return {
2✔
32
      code: CONFLICT,
33
      body: {
34
        error: error.message,
35
        details: {
36
          // TODO: improve this
37
          keyPattern: error.keyPattern,
38
          keyValue: error.keyValue
39
        }
40
        // code: error.code,
41
        // keyPattern: error.keyPattern,
42
        // keyValue: error.keyValue,
43
      }
44
    }
45
  }
46

47
  // en caso de que no se sepa qué error es
NEW
48
  return {
×
49
    code: INTERNAL_SERVER_ERROR,
50
    body: {
51
      // TODO: create unknown response
52
      error: 'Internal Server error',
53
      details: {
54
        error: 'Internal Server error'
55
      }
56
    }
57
  }
58
}
59

60
export default handleErrorResponse
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc