error.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package baidu
  2. import (
  3. "net/http"
  4. "strconv"
  5. "github.com/labring/aiproxy/core/relay/adaptor"
  6. relaymodel "github.com/labring/aiproxy/core/relay/model"
  7. )
  8. // https://cloud.baidu.com/doc/WENXINWORKSHOP/s/tlmyncueh
  9. func ErrorHandler(baiduError *Error) adaptor.Error {
  10. switch baiduError.ErrorCode {
  11. case 13, 14, 100, 110:
  12. return relaymodel.WrapperOpenAIErrorWithMessage(
  13. baiduError.ErrorMsg,
  14. "upstream_"+strconv.Itoa(baiduError.ErrorCode),
  15. http.StatusUnauthorized,
  16. )
  17. case 17, 19, 111:
  18. return relaymodel.WrapperOpenAIErrorWithMessage(
  19. baiduError.ErrorMsg,
  20. "upstream_"+strconv.Itoa(baiduError.ErrorCode),
  21. http.StatusForbidden,
  22. )
  23. case 336001, 336002, 336003,
  24. 336005, 336006, 336007,
  25. 336008, 336103, 336104,
  26. 336106, 336118, 336122,
  27. 336123, 336221, 337006,
  28. 337008, 337009:
  29. return relaymodel.WrapperOpenAIErrorWithMessage(
  30. baiduError.ErrorMsg,
  31. "upstream_"+strconv.Itoa(baiduError.ErrorCode),
  32. http.StatusBadRequest,
  33. )
  34. case 4, 18, 336117, 336501, 336502,
  35. 336503, 336504, 336505,
  36. 336507:
  37. return relaymodel.WrapperOpenAIErrorWithMessage(
  38. baiduError.ErrorMsg,
  39. "upstream_"+strconv.Itoa(baiduError.ErrorCode),
  40. http.StatusTooManyRequests,
  41. )
  42. }
  43. return relaymodel.WrapperOpenAIErrorWithMessage(
  44. baiduError.ErrorMsg,
  45. "upstream_"+strconv.Itoa(baiduError.ErrorCode),
  46. http.StatusInternalServerError,
  47. )
  48. }