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

supabase / storage / 25943741866

15 May 2026 10:08PM UTC coverage: 40.677% (-34.4%) from 75.075%
25943741866

Pull #1108

github

web-flow
Merge 4205c3758 into e58e4ab42
Pull Request #1108: feat: add on-demand signature generation

2193 of 5987 branches covered (36.63%)

Branch coverage included in aggregate %.

105 of 118 new or added lines in 5 files covered. (88.98%)

3707 existing lines in 165 files now uncovered.

4419 of 10268 relevant lines covered (43.04%)

35.28 hits per line

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

51.02
/src/http/error-handler.ts
1
import { FastifyError } from '@fastify/error'
2
import { ErrorCode, isRenderableError, StorageBackendError, StorageError } from '@internal/errors'
3
import { isDatabaseSlowDownError } from '@internal/errors/database-error'
4
import { FastifyInstance } from 'fastify'
5

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

26
    // database error
27
    if (isDatabaseSlowDownError(error)) {
4!
28
      return reply.status(429).send(
×
29
        formatter({
30
          statusCode: `429`,
31
          error: 'too_many_connections',
32
          code: ErrorCode.SlowDown,
33
          message: 'Too many connections issued to the database',
34
        })
35
      )
36
    }
37

38
    if (isRenderableError(error)) {
4!
39
      const renderableError = error.render()
4✔
40
      const statusCode = options?.respectStatusCode
4!
41
        ? parseInt(renderableError.statusCode, 10)
42
        : error.userStatusCode
4!
43
          ? error.userStatusCode
44
          : renderableError.statusCode === '500'
×
45
            ? 500
46
            : 400
47

48
      if (
4✔
49
        renderableError.code === ErrorCode.AbortedTerminate ||
12✔
50
        (error instanceof StorageBackendError && error.shouldCloseConnection())
51
      ) {
52
        reply.header('Connection', 'close')
1✔
53

54
        reply.raw.once('finish', () => {
1✔
55
          setTimeout(() => {
1✔
56
            if (!request.raw.closed) {
×
57
              request.raw.destroy()
×
58
            }
59
          }, 3000)
60
        })
61
      }
62

63
      return reply.status(statusCode).send(
4✔
64
        formatter({
65
          ...renderableError,
66
          error: error.error || renderableError.code,
4!
67
        })
68
      )
69
    }
70

71
    // Fastify errors
UNCOV
72
    if ('statusCode' in error) {
×
UNCOV
73
      const err = error as FastifyError
×
74

UNCOV
75
      if (err.code === 'FST_ERR_CTP_INVALID_MEDIA_TYPE') {
×
UNCOV
76
        return reply.status(400).send(
×
77
          formatter({
78
            statusCode: '415',
79
            code: ErrorCode.InvalidMimeType,
80
            error: 'invalid_mime_type',
81
            message: 'Invalid Content-Type header',
82
          })
83
        )
84
      }
85

UNCOV
86
      return reply.status(err.statusCode || 500).send(
×
87
        formatter({
88
          statusCode: `${err.statusCode}`,
89
          error: err.name,
90
          code: ErrorCode.InternalError,
91
          message: err.message,
92
        })
93
      )
94
    }
95

UNCOV
96
    return reply.status(500).send(
×
97
      formatter({
98
        statusCode: '500',
99
        error: 'Internal',
100
        message: 'Internal Server Error',
101
        code: ErrorCode.InternalError,
102
      })
103
    )
104
  })
105
}
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