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

supabase / storage / 27006922300

05 Jun 2026 09:26AM UTC coverage: 42.632% (-33.7%) from 76.354%
27006922300

Pull #1136

github

web-flow
Merge 430e0a175 into 4e1530849
Pull Request #1136: chore(ci): extract common deps setup

2485 of 6429 branches covered (38.65%)

Branch coverage included in aggregate %.

4887 of 10863 relevant lines covered (44.99%)

34.24 hits per line

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

72.22
/src/http/error-handler.ts
1
import { FastifyError } from '@fastify/error'
2
import {
3
  ErrorCode,
4
  getErrorCode,
5
  isRenderableError,
6
  StorageBackendError,
7
  StorageError,
8
} from '@internal/errors'
9
import { isDatabaseSlowDownError } from '@internal/errors/database-error'
10
import { FastifyInstance } from 'fastify'
11

12
/**
13
 * The global error handler for all the uncaught exceptions within a request.
14
 * We try our best to display meaningful information to our users
15
 * and log any error that occurs
16
 * @param app
17
 * @param options
18
 */
19
export const setErrorHandler = (
4✔
20
  app: FastifyInstance,
21
  options?: {
22
    respectStatusCode?: boolean
23
    formatter?: (error: StorageError) => Record<string, unknown>
24
  }
25
) => {
26
  app.setErrorHandler<Error>(function (error, request, reply) {
11✔
27
    const formatter = options?.formatter || ((e) => e)
6✔
28
    // We assign the error received.
29
    // it will be logged in the request log plugin
30
    request.executionError = error
6✔
31

32
    // database error
33
    if (isDatabaseSlowDownError(error)) {
6!
34
      return reply.status(429).send(
×
35
        formatter({
36
          statusCode: `429`,
37
          error: 'too_many_connections',
38
          code: ErrorCode.SlowDown,
39
          message: 'Too many connections issued to the database',
40
        })
41
      )
42
    }
43

44
    if (isRenderableError(error)) {
6✔
45
      const renderableError = error.render()
4✔
46
      const statusCode = options?.respectStatusCode
4!
47
        ? parseInt(renderableError.statusCode, 10)
48
        : error.userStatusCode
4!
49
          ? error.userStatusCode
50
          : renderableError.statusCode === '500'
×
51
            ? 500
52
            : 400
53

54
      if (
4✔
55
        renderableError.code === ErrorCode.AbortedTerminate ||
12✔
56
        (error instanceof StorageBackendError && error.shouldCloseConnection())
57
      ) {
58
        reply.header('Connection', 'close')
1✔
59

60
        reply.raw.once('finish', () => {
1✔
61
          setTimeout(() => {
1✔
62
            if (!request.raw.closed) {
×
63
              request.raw.destroy()
×
64
            }
65
          }, 3000)
66
        })
67
      }
68

69
      return reply.status(statusCode).send(
4✔
70
        formatter({
71
          ...renderableError,
72
          error: error.error || renderableError.code,
4!
73
        })
74
      )
75
    }
76

77
    // Fastify errors
78
    if ('statusCode' in error) {
2!
79
      const err = error as FastifyError
2✔
80

81
      if (err.code === 'FST_ERR_CTP_INVALID_MEDIA_TYPE') {
2!
82
        return reply.status(400).send(
×
83
          formatter({
84
            statusCode: '415',
85
            code: ErrorCode.InvalidMimeType,
86
            error: 'invalid_mime_type',
87
            message: 'Invalid Content-Type header',
88
          })
89
        )
90
      }
91

92
      const errorCode = getErrorCode(err)
2✔
93
      const responseErrorCode = (
94
        errorCode === ErrorCode.UnknownError ? ErrorCode.InternalError : errorCode
2✔
95
      ) as ErrorCode
96
      const responseStatusCode = err.statusCode || 500
2✔
97

98
      return reply.status(responseStatusCode).send(
2✔
99
        formatter({
100
          statusCode: `${responseStatusCode}`,
101
          error: err.name,
102
          code: responseErrorCode,
103
          message: err.message,
104
        })
105
      )
106
    }
107

108
    return reply.status(500).send(
×
109
      formatter({
110
        statusCode: '500',
111
        error: 'Internal',
112
        message: 'Internal Server Error',
113
        code: ErrorCode.InternalError,
114
      })
115
    )
116
  })
117
}
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

© 2026 Coveralls, Inc