Coverage for functions \ flipdare \ error \ callable_error_code.py: 89%

9 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

3# 

4# This file is part of Flipdare's proprietary software and contains 

5# confidential and copyrighted material. Unauthorised copying, 

6# modification, distribution, or use of this file is strictly 

7# prohibited without prior written permission from Flipdare Pty Ltd. 

8# 

9# This software includes third-party components licensed under MIT, 

10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

11# 

12 

13 

14from firebase_functions import https_fn 

15 

16__all__ = ["CallableErrorCode", "HTTP_TO_FB_CODE"] 

17 

18_F = https_fn.FunctionsErrorCode 

19 

20# ref: firebase_functions/https_fn.py 

21# ref: https://github.com/grpc/grpc/blob/master/doc/statuscodes.md 

22HTTP_TO_FB_CODE = { 

23 400: _F.INVALID_ARGUMENT, # 400 in firebase 

24 401: _F.UNAUTHENTICATED, # 401 in firebase 

25 403: _F.PERMISSION_DENIED, # 403 in firebase 

26 404: _F.NOT_FOUND, # 404 in firebase 

27 422: _F.FAILED_PRECONDITION, # 422 in firebase 

28 500: _F.INTERNAL, # 500 in firebase 

29 503: _F.UNAVAILABLE, # 503 in firebase 

30 # firebase functions specific 

31 409: _F.ALREADY_EXISTS, # from firebase 

32 504: _F.DEADLINE_EXCEEDED, # from firebase 

33 429: _F.RESOURCE_EXHAUSTED, # from firebase 

34 501: _F.UNIMPLEMENTED, # from firebase 

35} 

36 

37 

38class CallableErrorCode: 

39 generic_error_code = _F.INTERNAL 

40 

41 @staticmethod 

42 def to_firebase(http_code: int) -> _F: 

43 return HTTP_TO_FB_CODE.get(http_code, _F.INTERNAL)