apierr_gen.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. package apierr
  2. import (
  3. common "kpt-tmr-group/proto/go/backend/common"
  4. "github.com/gin-gonic/gin"
  5. )
  6. // NewErrUnauthorized create err with default message
  7. func NewErrUnauthorized(err ...error) *Error {
  8. return New(common.Error_UNAUTHORIZED).With(err...)
  9. }
  10. // ErrUnauthorized create err with locales
  11. func ErrUnauthorized(c *gin.Context, err ...error) *Error {
  12. return WithContext(c, common.Error_UNAUTHORIZED).With(err...)
  13. }
  14. // AbortUnauthorized abort with status code and log common.Error_UNAUTHORIZED to newrelic
  15. func AbortUnauthorized(c *gin.Context, code int, err ...error) {
  16. for _, e := range err {
  17. // if err is nil, gin will panic
  18. if e != nil {
  19. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  20. if !shouldIgnoreCode(code) {
  21. c.Error(e)
  22. }
  23. }
  24. }
  25. c.AbortWithStatusJSON(code, ErrUnauthorized(c, err...))
  26. }
  27. // AbortStatusUnauthorized abort with status code and log common.Error_UNAUTHORIZED to newrelic
  28. func AbortStatusUnauthorized(c *gin.Context, err ...error) {
  29. AbortUnauthorized(c, 401, err...)
  30. }
  31. // NewErrBadRequest create err with default message
  32. func NewErrBadRequest(err ...error) *Error {
  33. return New(common.Error_BAD_REQUEST).With(err...)
  34. }
  35. // ErrBadRequest create err with locales
  36. func ErrBadRequest(c *gin.Context, err ...error) *Error {
  37. return WithContext(c, common.Error_BAD_REQUEST).With(err...)
  38. }
  39. // AbortBadRequest abort with status code and log common.Error_BAD_REQUEST to newrelic
  40. func AbortBadRequest(c *gin.Context, code int, err ...error) {
  41. for _, e := range err {
  42. // if err is nil, gin will panic
  43. if e != nil {
  44. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  45. if !shouldIgnoreCode(code) {
  46. c.Error(e)
  47. }
  48. }
  49. }
  50. c.AbortWithStatusJSON(code, ErrBadRequest(c, err...))
  51. }
  52. // AbortStatusBadRequest abort with status code and log common.Error_BAD_REQUEST to newrelic
  53. func AbortStatusBadRequest(c *gin.Context, err ...error) {
  54. AbortBadRequest(c, 400, err...)
  55. }
  56. // NewErrInvalidContentType create err with default message
  57. func NewErrInvalidContentType(err ...error) *Error {
  58. return New(common.Error_INVALID_CONTENT_TYPE).With(err...)
  59. }
  60. // ErrInvalidContentType create err with locales
  61. func ErrInvalidContentType(c *gin.Context, err ...error) *Error {
  62. return WithContext(c, common.Error_INVALID_CONTENT_TYPE).With(err...)
  63. }
  64. // AbortInvalidContentType abort with status code and log common.Error_INVALID_CONTENT_TYPE to newrelic
  65. func AbortInvalidContentType(c *gin.Context, code int, err ...error) {
  66. for _, e := range err {
  67. // if err is nil, gin will panic
  68. if e != nil {
  69. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  70. if !shouldIgnoreCode(code) {
  71. c.Error(e)
  72. }
  73. }
  74. }
  75. c.AbortWithStatusJSON(code, ErrInvalidContentType(c, err...))
  76. }
  77. // AbortStatusInvalidContentType abort with status code and log common.Error_INVALID_CONTENT_TYPE to newrelic
  78. func AbortStatusInvalidContentType(c *gin.Context, err ...error) {
  79. AbortInvalidContentType(c, 400, err...)
  80. }
  81. // NewErrInvalidContentEncoding create err with default message
  82. func NewErrInvalidContentEncoding(err ...error) *Error {
  83. return New(common.Error_INVALID_CONTENT_ENCODING).With(err...)
  84. }
  85. // ErrInvalidContentEncoding create err with locales
  86. func ErrInvalidContentEncoding(c *gin.Context, err ...error) *Error {
  87. return WithContext(c, common.Error_INVALID_CONTENT_ENCODING).With(err...)
  88. }
  89. // AbortInvalidContentEncoding abort with status code and log common.Error_INVALID_CONTENT_ENCODING to newrelic
  90. func AbortInvalidContentEncoding(c *gin.Context, code int, err ...error) {
  91. for _, e := range err {
  92. // if err is nil, gin will panic
  93. if e != nil {
  94. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  95. if !shouldIgnoreCode(code) {
  96. c.Error(e)
  97. }
  98. }
  99. }
  100. c.AbortWithStatusJSON(code, ErrInvalidContentEncoding(c, err...))
  101. }
  102. // AbortStatusInvalidContentEncoding abort with status code and log common.Error_INVALID_CONTENT_ENCODING to newrelic
  103. func AbortStatusInvalidContentEncoding(c *gin.Context, err ...error) {
  104. AbortInvalidContentEncoding(c, 400, err...)
  105. }
  106. // NewErrTooManyRequests create err with default message
  107. func NewErrTooManyRequests(err ...error) *Error {
  108. return New(common.Error_TOO_MANY_REQUESTS).With(err...)
  109. }
  110. // ErrTooManyRequests create err with locales
  111. func ErrTooManyRequests(c *gin.Context, err ...error) *Error {
  112. return WithContext(c, common.Error_TOO_MANY_REQUESTS).With(err...)
  113. }
  114. // AbortTooManyRequests abort with status code and log common.Error_TOO_MANY_REQUESTS to newrelic
  115. func AbortTooManyRequests(c *gin.Context, code int, err ...error) {
  116. for _, e := range err {
  117. // if err is nil, gin will panic
  118. if e != nil {
  119. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  120. if !shouldIgnoreCode(code) {
  121. c.Error(e)
  122. }
  123. }
  124. }
  125. c.AbortWithStatusJSON(code, ErrTooManyRequests(c, err...))
  126. }
  127. // AbortStatusTooManyRequests abort with status code and log common.Error_TOO_MANY_REQUESTS to newrelic
  128. func AbortStatusTooManyRequests(c *gin.Context, err ...error) {
  129. AbortTooManyRequests(c, 429, err...)
  130. }
  131. // NewErrInvalidStorageType create err with default message
  132. func NewErrInvalidStorageType(err ...error) *Error {
  133. return New(common.Error_INVALID_STORAGE_TYPE).With(err...)
  134. }
  135. // ErrInvalidStorageType create err with locales
  136. func ErrInvalidStorageType(c *gin.Context, err ...error) *Error {
  137. return WithContext(c, common.Error_INVALID_STORAGE_TYPE).With(err...)
  138. }
  139. // AbortInvalidStorageType abort with status code and log common.Error_INVALID_STORAGE_TYPE to newrelic
  140. func AbortInvalidStorageType(c *gin.Context, code int, err ...error) {
  141. for _, e := range err {
  142. // if err is nil, gin will panic
  143. if e != nil {
  144. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  145. if !shouldIgnoreCode(code) {
  146. c.Error(e)
  147. }
  148. }
  149. }
  150. c.AbortWithStatusJSON(code, ErrInvalidStorageType(c, err...))
  151. }
  152. // AbortStatusInvalidStorageType abort with status code and log common.Error_INVALID_STORAGE_TYPE to newrelic
  153. func AbortStatusInvalidStorageType(c *gin.Context, err ...error) {
  154. AbortInvalidStorageType(c, 400, err...)
  155. }
  156. // NewErrInvalidDeData create err with default message
  157. func NewErrInvalidDeData(err ...error) *Error {
  158. return New(common.Error_INVALID_DE_DATA).With(err...)
  159. }
  160. // ErrInvalidDeData create err with locales
  161. func ErrInvalidDeData(c *gin.Context, err ...error) *Error {
  162. return WithContext(c, common.Error_INVALID_DE_DATA).With(err...)
  163. }
  164. // AbortInvalidDeData abort with status code and log common.Error_INVALID_DE_DATA to newrelic
  165. func AbortInvalidDeData(c *gin.Context, code int, err ...error) {
  166. for _, e := range err {
  167. // if err is nil, gin will panic
  168. if e != nil {
  169. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  170. if !shouldIgnoreCode(code) {
  171. c.Error(e)
  172. }
  173. }
  174. }
  175. c.AbortWithStatusJSON(code, ErrInvalidDeData(c, err...))
  176. }
  177. // AbortStatusInvalidDeData abort with status code and log common.Error_INVALID_DE_DATA to newrelic
  178. func AbortStatusInvalidDeData(c *gin.Context, err ...error) {
  179. AbortInvalidDeData(c, 400, err...)
  180. }
  181. // NewErrCheckinRepeated create err with default message
  182. func NewErrCheckinRepeated(err ...error) *Error {
  183. return New(common.Error_CHECKIN_REPEATED).With(err...)
  184. }
  185. // ErrCheckinRepeated create err with locales
  186. func ErrCheckinRepeated(c *gin.Context, err ...error) *Error {
  187. return WithContext(c, common.Error_CHECKIN_REPEATED).With(err...)
  188. }
  189. // AbortCheckinRepeated abort with status code and log common.Error_CHECKIN_REPEATED to newrelic
  190. func AbortCheckinRepeated(c *gin.Context, code int, err ...error) {
  191. for _, e := range err {
  192. // if err is nil, gin will panic
  193. if e != nil {
  194. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  195. if !shouldIgnoreCode(code) {
  196. c.Error(e)
  197. }
  198. }
  199. }
  200. c.AbortWithStatusJSON(code, ErrCheckinRepeated(c, err...))
  201. }
  202. // AbortStatusCheckinRepeated abort with status code and log common.Error_CHECKIN_REPEATED to newrelic
  203. func AbortStatusCheckinRepeated(c *gin.Context, err ...error) {
  204. AbortCheckinRepeated(c, 400, err...)
  205. }
  206. // NewErrCourseNotFound create err with default message
  207. func NewErrCourseNotFound(err ...error) *Error {
  208. return New(common.Error_COURSE_NOT_FOUND).With(err...)
  209. }
  210. // ErrCourseNotFound create err with locales
  211. func ErrCourseNotFound(c *gin.Context, err ...error) *Error {
  212. return WithContext(c, common.Error_COURSE_NOT_FOUND).With(err...)
  213. }
  214. // AbortCourseNotFound abort with status code and log common.Error_COURSE_NOT_FOUND to newrelic
  215. func AbortCourseNotFound(c *gin.Context, code int, err ...error) {
  216. for _, e := range err {
  217. // if err is nil, gin will panic
  218. if e != nil {
  219. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  220. if !shouldIgnoreCode(code) {
  221. c.Error(e)
  222. }
  223. }
  224. }
  225. c.AbortWithStatusJSON(code, ErrCourseNotFound(c, err...))
  226. }
  227. // AbortStatusCourseNotFound abort with status code and log common.Error_COURSE_NOT_FOUND to newrelic
  228. func AbortStatusCourseNotFound(c *gin.Context, err ...error) {
  229. AbortCourseNotFound(c, 400, err...)
  230. }
  231. // NewErrCourseNotInterest create err with default message
  232. func NewErrCourseNotInterest(err ...error) *Error {
  233. return New(common.Error_COURSE_NOT_INTEREST).With(err...)
  234. }
  235. // ErrCourseNotInterest create err with locales
  236. func ErrCourseNotInterest(c *gin.Context, err ...error) *Error {
  237. return WithContext(c, common.Error_COURSE_NOT_INTEREST).With(err...)
  238. }
  239. // AbortCourseNotInterest abort with status code and log common.Error_COURSE_NOT_INTEREST to newrelic
  240. func AbortCourseNotInterest(c *gin.Context, code int, err ...error) {
  241. for _, e := range err {
  242. // if err is nil, gin will panic
  243. if e != nil {
  244. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  245. if !shouldIgnoreCode(code) {
  246. c.Error(e)
  247. }
  248. }
  249. }
  250. c.AbortWithStatusJSON(code, ErrCourseNotInterest(c, err...))
  251. }
  252. // AbortStatusCourseNotInterest abort with status code and log common.Error_COURSE_NOT_INTEREST to newrelic
  253. func AbortStatusCourseNotInterest(c *gin.Context, err ...error) {
  254. AbortCourseNotInterest(c, 500, err...)
  255. }
  256. // NewErrModuleNotFound create err with default message
  257. func NewErrModuleNotFound(err ...error) *Error {
  258. return New(common.Error_MODULE_NOT_FOUND).With(err...)
  259. }
  260. // ErrModuleNotFound create err with locales
  261. func ErrModuleNotFound(c *gin.Context, err ...error) *Error {
  262. return WithContext(c, common.Error_MODULE_NOT_FOUND).With(err...)
  263. }
  264. // AbortModuleNotFound abort with status code and log common.Error_MODULE_NOT_FOUND to newrelic
  265. func AbortModuleNotFound(c *gin.Context, code int, err ...error) {
  266. for _, e := range err {
  267. // if err is nil, gin will panic
  268. if e != nil {
  269. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  270. if !shouldIgnoreCode(code) {
  271. c.Error(e)
  272. }
  273. }
  274. }
  275. c.AbortWithStatusJSON(code, ErrModuleNotFound(c, err...))
  276. }
  277. // AbortStatusModuleNotFound abort with status code and log common.Error_MODULE_NOT_FOUND to newrelic
  278. func AbortStatusModuleNotFound(c *gin.Context, err ...error) {
  279. AbortModuleNotFound(c, 400, err...)
  280. }
  281. // NewErrUserCourseAlreadyAdded create err with default message
  282. func NewErrUserCourseAlreadyAdded(err ...error) *Error {
  283. return New(common.Error_USER_COURSE_ALREADY_ADDED).With(err...)
  284. }
  285. // ErrUserCourseAlreadyAdded create err with locales
  286. func ErrUserCourseAlreadyAdded(c *gin.Context, err ...error) *Error {
  287. return WithContext(c, common.Error_USER_COURSE_ALREADY_ADDED).With(err...)
  288. }
  289. // AbortUserCourseAlreadyAdded abort with status code and log common.Error_USER_COURSE_ALREADY_ADDED to newrelic
  290. func AbortUserCourseAlreadyAdded(c *gin.Context, code int, err ...error) {
  291. for _, e := range err {
  292. // if err is nil, gin will panic
  293. if e != nil {
  294. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  295. if !shouldIgnoreCode(code) {
  296. c.Error(e)
  297. }
  298. }
  299. }
  300. c.AbortWithStatusJSON(code, ErrUserCourseAlreadyAdded(c, err...))
  301. }
  302. // AbortStatusUserCourseAlreadyAdded abort with status code and log common.Error_USER_COURSE_ALREADY_ADDED to newrelic
  303. func AbortStatusUserCourseAlreadyAdded(c *gin.Context, err ...error) {
  304. AbortUserCourseAlreadyAdded(c, 400, err...)
  305. }
  306. // NewErrUserCourseNotFound create err with default message
  307. func NewErrUserCourseNotFound(err ...error) *Error {
  308. return New(common.Error_USER_COURSE_NOT_FOUND).With(err...)
  309. }
  310. // ErrUserCourseNotFound create err with locales
  311. func ErrUserCourseNotFound(c *gin.Context, err ...error) *Error {
  312. return WithContext(c, common.Error_USER_COURSE_NOT_FOUND).With(err...)
  313. }
  314. // AbortUserCourseNotFound abort with status code and log common.Error_USER_COURSE_NOT_FOUND to newrelic
  315. func AbortUserCourseNotFound(c *gin.Context, code int, err ...error) {
  316. for _, e := range err {
  317. // if err is nil, gin will panic
  318. if e != nil {
  319. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  320. if !shouldIgnoreCode(code) {
  321. c.Error(e)
  322. }
  323. }
  324. }
  325. c.AbortWithStatusJSON(code, ErrUserCourseNotFound(c, err...))
  326. }
  327. // AbortStatusUserCourseNotFound abort with status code and log common.Error_USER_COURSE_NOT_FOUND to newrelic
  328. func AbortStatusUserCourseNotFound(c *gin.Context, err ...error) {
  329. AbortUserCourseNotFound(c, 400, err...)
  330. }
  331. // NewErrPtLimited create err with default message
  332. func NewErrPtLimited(err ...error) *Error {
  333. return New(common.Error_PT_LIMITED).With(err...)
  334. }
  335. // ErrPtLimited create err with locales
  336. func ErrPtLimited(c *gin.Context, err ...error) *Error {
  337. return WithContext(c, common.Error_PT_LIMITED).With(err...)
  338. }
  339. // AbortPtLimited abort with status code and log common.Error_PT_LIMITED to newrelic
  340. func AbortPtLimited(c *gin.Context, code int, err ...error) {
  341. for _, e := range err {
  342. // if err is nil, gin will panic
  343. if e != nil {
  344. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  345. if !shouldIgnoreCode(code) {
  346. c.Error(e)
  347. }
  348. }
  349. }
  350. c.AbortWithStatusJSON(code, ErrPtLimited(c, err...))
  351. }
  352. // AbortStatusPtLimited abort with status code and log common.Error_PT_LIMITED to newrelic
  353. func AbortStatusPtLimited(c *gin.Context, err ...error) {
  354. AbortPtLimited(c, 400, err...)
  355. }
  356. // NewErrInvalidPrice create err with default message
  357. func NewErrInvalidPrice(err ...error) *Error {
  358. return New(common.Error_INVALID_PRICE).With(err...)
  359. }
  360. // ErrInvalidPrice create err with locales
  361. func ErrInvalidPrice(c *gin.Context, err ...error) *Error {
  362. return WithContext(c, common.Error_INVALID_PRICE).With(err...)
  363. }
  364. // AbortInvalidPrice abort with status code and log common.Error_INVALID_PRICE to newrelic
  365. func AbortInvalidPrice(c *gin.Context, code int, err ...error) {
  366. for _, e := range err {
  367. // if err is nil, gin will panic
  368. if e != nil {
  369. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  370. if !shouldIgnoreCode(code) {
  371. c.Error(e)
  372. }
  373. }
  374. }
  375. c.AbortWithStatusJSON(code, ErrInvalidPrice(c, err...))
  376. }
  377. // AbortStatusInvalidPrice abort with status code and log common.Error_INVALID_PRICE to newrelic
  378. func AbortStatusInvalidPrice(c *gin.Context, err ...error) {
  379. AbortInvalidPrice(c, 400, err...)
  380. }
  381. // NewErrInvalidProductId create err with default message
  382. func NewErrInvalidProductId(err ...error) *Error {
  383. return New(common.Error_INVALID_PRODUCT_ID).With(err...)
  384. }
  385. // ErrInvalidProductId create err with locales
  386. func ErrInvalidProductId(c *gin.Context, err ...error) *Error {
  387. return WithContext(c, common.Error_INVALID_PRODUCT_ID).With(err...)
  388. }
  389. // AbortInvalidProductId abort with status code and log common.Error_INVALID_PRODUCT_ID to newrelic
  390. func AbortInvalidProductId(c *gin.Context, code int, err ...error) {
  391. for _, e := range err {
  392. // if err is nil, gin will panic
  393. if e != nil {
  394. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  395. if !shouldIgnoreCode(code) {
  396. c.Error(e)
  397. }
  398. }
  399. }
  400. c.AbortWithStatusJSON(code, ErrInvalidProductId(c, err...))
  401. }
  402. // AbortStatusInvalidProductId abort with status code and log common.Error_INVALID_PRODUCT_ID to newrelic
  403. func AbortStatusInvalidProductId(c *gin.Context, err ...error) {
  404. AbortInvalidProductId(c, 400, err...)
  405. }
  406. // NewErrInvalidOrderNumber create err with default message
  407. func NewErrInvalidOrderNumber(err ...error) *Error {
  408. return New(common.Error_INVALID_ORDER_NUMBER).With(err...)
  409. }
  410. // ErrInvalidOrderNumber create err with locales
  411. func ErrInvalidOrderNumber(c *gin.Context, err ...error) *Error {
  412. return WithContext(c, common.Error_INVALID_ORDER_NUMBER).With(err...)
  413. }
  414. // AbortInvalidOrderNumber abort with status code and log common.Error_INVALID_ORDER_NUMBER to newrelic
  415. func AbortInvalidOrderNumber(c *gin.Context, code int, err ...error) {
  416. for _, e := range err {
  417. // if err is nil, gin will panic
  418. if e != nil {
  419. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  420. if !shouldIgnoreCode(code) {
  421. c.Error(e)
  422. }
  423. }
  424. }
  425. c.AbortWithStatusJSON(code, ErrInvalidOrderNumber(c, err...))
  426. }
  427. // AbortStatusInvalidOrderNumber abort with status code and log common.Error_INVALID_ORDER_NUMBER to newrelic
  428. func AbortStatusInvalidOrderNumber(c *gin.Context, err ...error) {
  429. AbortInvalidOrderNumber(c, 400, err...)
  430. }
  431. // NewErrInvalidUserId create err with default message
  432. func NewErrInvalidUserId(err ...error) *Error {
  433. return New(common.Error_INVALID_USER_ID).With(err...)
  434. }
  435. // ErrInvalidUserId create err with locales
  436. func ErrInvalidUserId(c *gin.Context, err ...error) *Error {
  437. return WithContext(c, common.Error_INVALID_USER_ID).With(err...)
  438. }
  439. // AbortInvalidUserId abort with status code and log common.Error_INVALID_USER_ID to newrelic
  440. func AbortInvalidUserId(c *gin.Context, code int, err ...error) {
  441. for _, e := range err {
  442. // if err is nil, gin will panic
  443. if e != nil {
  444. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  445. if !shouldIgnoreCode(code) {
  446. c.Error(e)
  447. }
  448. }
  449. }
  450. c.AbortWithStatusJSON(code, ErrInvalidUserId(c, err...))
  451. }
  452. // AbortStatusInvalidUserId abort with status code and log common.Error_INVALID_USER_ID to newrelic
  453. func AbortStatusInvalidUserId(c *gin.Context, err ...error) {
  454. AbortInvalidUserId(c, 400, err...)
  455. }
  456. // NewErrInvalidReceipt create err with default message
  457. func NewErrInvalidReceipt(err ...error) *Error {
  458. return New(common.Error_INVALID_RECEIPT).With(err...)
  459. }
  460. // ErrInvalidReceipt create err with locales
  461. func ErrInvalidReceipt(c *gin.Context, err ...error) *Error {
  462. return WithContext(c, common.Error_INVALID_RECEIPT).With(err...)
  463. }
  464. // AbortInvalidReceipt abort with status code and log common.Error_INVALID_RECEIPT to newrelic
  465. func AbortInvalidReceipt(c *gin.Context, code int, err ...error) {
  466. for _, e := range err {
  467. // if err is nil, gin will panic
  468. if e != nil {
  469. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  470. if !shouldIgnoreCode(code) {
  471. c.Error(e)
  472. }
  473. }
  474. }
  475. c.AbortWithStatusJSON(code, ErrInvalidReceipt(c, err...))
  476. }
  477. // AbortStatusInvalidReceipt abort with status code and log common.Error_INVALID_RECEIPT to newrelic
  478. func AbortStatusInvalidReceipt(c *gin.Context, err ...error) {
  479. AbortInvalidReceipt(c, 400, err...)
  480. }
  481. // NewErrEmptyIosReceipt create err with default message
  482. func NewErrEmptyIosReceipt(err ...error) *Error {
  483. return New(common.Error_EMPTY_IOS_RECEIPT).With(err...)
  484. }
  485. // ErrEmptyIosReceipt create err with locales
  486. func ErrEmptyIosReceipt(c *gin.Context, err ...error) *Error {
  487. return WithContext(c, common.Error_EMPTY_IOS_RECEIPT).With(err...)
  488. }
  489. // AbortEmptyIosReceipt abort with status code and log common.Error_EMPTY_IOS_RECEIPT to newrelic
  490. func AbortEmptyIosReceipt(c *gin.Context, code int, err ...error) {
  491. for _, e := range err {
  492. // if err is nil, gin will panic
  493. if e != nil {
  494. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  495. if !shouldIgnoreCode(code) {
  496. c.Error(e)
  497. }
  498. }
  499. }
  500. c.AbortWithStatusJSON(code, ErrEmptyIosReceipt(c, err...))
  501. }
  502. // AbortStatusEmptyIosReceipt abort with status code and log common.Error_EMPTY_IOS_RECEIPT to newrelic
  503. func AbortStatusEmptyIosReceipt(c *gin.Context, err ...error) {
  504. AbortEmptyIosReceipt(c, 500, err...)
  505. }
  506. // NewErrUserPlanLimitedCourseCount create err with default message
  507. func NewErrUserPlanLimitedCourseCount(err ...error) *Error {
  508. return New(common.Error_USER_PLAN_LIMITED_COURSE_COUNT).With(err...)
  509. }
  510. // ErrUserPlanLimitedCourseCount create err with locales
  511. func ErrUserPlanLimitedCourseCount(c *gin.Context, err ...error) *Error {
  512. return WithContext(c, common.Error_USER_PLAN_LIMITED_COURSE_COUNT).With(err...)
  513. }
  514. // AbortUserPlanLimitedCourseCount abort with status code and log common.Error_USER_PLAN_LIMITED_COURSE_COUNT to newrelic
  515. func AbortUserPlanLimitedCourseCount(c *gin.Context, code int, err ...error) {
  516. for _, e := range err {
  517. // if err is nil, gin will panic
  518. if e != nil {
  519. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  520. if !shouldIgnoreCode(code) {
  521. c.Error(e)
  522. }
  523. }
  524. }
  525. c.AbortWithStatusJSON(code, ErrUserPlanLimitedCourseCount(c, err...))
  526. }
  527. // AbortStatusUserPlanLimitedCourseCount abort with status code and log common.Error_USER_PLAN_LIMITED_COURSE_COUNT to newrelic
  528. func AbortStatusUserPlanLimitedCourseCount(c *gin.Context, err ...error) {
  529. AbortUserPlanLimitedCourseCount(c, 500, err...)
  530. }
  531. // NewErrInternalError create err with default message
  532. func NewErrInternalError(err ...error) *Error {
  533. return New(common.Error_INTERNAL_ERROR).With(err...)
  534. }
  535. // ErrInternalError create err with locales
  536. func ErrInternalError(c *gin.Context, err ...error) *Error {
  537. return WithContext(c, common.Error_INTERNAL_ERROR).With(err...)
  538. }
  539. // AbortInternalError abort with status code and log common.Error_INTERNAL_ERROR to newrelic
  540. func AbortInternalError(c *gin.Context, code int, err ...error) {
  541. for _, e := range err {
  542. // if err is nil, gin will panic
  543. if e != nil {
  544. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  545. if !shouldIgnoreCode(code) {
  546. c.Error(e)
  547. }
  548. }
  549. }
  550. c.AbortWithStatusJSON(code, ErrInternalError(c, err...))
  551. }
  552. // AbortStatusInternalError abort with status code and log common.Error_INTERNAL_ERROR to newrelic
  553. func AbortStatusInternalError(c *gin.Context, err ...error) {
  554. AbortInternalError(c, 500, err...)
  555. }
  556. // NewErrJsonpbError create err with default message
  557. func NewErrJsonpbError(err ...error) *Error {
  558. return New(common.Error_JSONPB_ERROR).With(err...)
  559. }
  560. // ErrJsonpbError create err with locales
  561. func ErrJsonpbError(c *gin.Context, err ...error) *Error {
  562. return WithContext(c, common.Error_JSONPB_ERROR).With(err...)
  563. }
  564. // AbortJsonpbError abort with status code and log common.Error_JSONPB_ERROR to newrelic
  565. func AbortJsonpbError(c *gin.Context, code int, err ...error) {
  566. for _, e := range err {
  567. // if err is nil, gin will panic
  568. if e != nil {
  569. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  570. if !shouldIgnoreCode(code) {
  571. c.Error(e)
  572. }
  573. }
  574. }
  575. c.AbortWithStatusJSON(code, ErrJsonpbError(c, err...))
  576. }
  577. // AbortStatusJsonpbError abort with status code and log common.Error_JSONPB_ERROR to newrelic
  578. func AbortStatusJsonpbError(c *gin.Context, err ...error) {
  579. AbortJsonpbError(c, 400, err...)
  580. }
  581. // NewErrJsonError create err with default message
  582. func NewErrJsonError(err ...error) *Error {
  583. return New(common.Error_JSON_ERROR).With(err...)
  584. }
  585. // ErrJsonError create err with locales
  586. func ErrJsonError(c *gin.Context, err ...error) *Error {
  587. return WithContext(c, common.Error_JSON_ERROR).With(err...)
  588. }
  589. // AbortJsonError abort with status code and log common.Error_JSON_ERROR to newrelic
  590. func AbortJsonError(c *gin.Context, code int, err ...error) {
  591. for _, e := range err {
  592. // if err is nil, gin will panic
  593. if e != nil {
  594. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  595. if !shouldIgnoreCode(code) {
  596. c.Error(e)
  597. }
  598. }
  599. }
  600. c.AbortWithStatusJSON(code, ErrJsonError(c, err...))
  601. }
  602. // AbortStatusJsonError abort with status code and log common.Error_JSON_ERROR to newrelic
  603. func AbortStatusJsonError(c *gin.Context, err ...error) {
  604. AbortJsonError(c, 400, err...)
  605. }
  606. // NewErrPbError create err with default message
  607. func NewErrPbError(err ...error) *Error {
  608. return New(common.Error_PB_ERROR).With(err...)
  609. }
  610. // ErrPbError create err with locales
  611. func ErrPbError(c *gin.Context, err ...error) *Error {
  612. return WithContext(c, common.Error_PB_ERROR).With(err...)
  613. }
  614. // AbortPbError abort with status code and log common.Error_PB_ERROR to newrelic
  615. func AbortPbError(c *gin.Context, code int, err ...error) {
  616. for _, e := range err {
  617. // if err is nil, gin will panic
  618. if e != nil {
  619. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  620. if !shouldIgnoreCode(code) {
  621. c.Error(e)
  622. }
  623. }
  624. }
  625. c.AbortWithStatusJSON(code, ErrPbError(c, err...))
  626. }
  627. // AbortStatusPbError abort with status code and log common.Error_PB_ERROR to newrelic
  628. func AbortStatusPbError(c *gin.Context, err ...error) {
  629. AbortPbError(c, 400, err...)
  630. }
  631. // NewErrExternalError create err with default message
  632. func NewErrExternalError(err ...error) *Error {
  633. return New(common.Error_EXTERNAL_ERROR).With(err...)
  634. }
  635. // ErrExternalError create err with locales
  636. func ErrExternalError(c *gin.Context, err ...error) *Error {
  637. return WithContext(c, common.Error_EXTERNAL_ERROR).With(err...)
  638. }
  639. // AbortExternalError abort with status code and log common.Error_EXTERNAL_ERROR to newrelic
  640. func AbortExternalError(c *gin.Context, code int, err ...error) {
  641. for _, e := range err {
  642. // if err is nil, gin will panic
  643. if e != nil {
  644. // so many 4xx error in new relic, only ignore 400/401/404 error, have fun!
  645. if !shouldIgnoreCode(code) {
  646. c.Error(e)
  647. }
  648. }
  649. }
  650. c.AbortWithStatusJSON(code, ErrExternalError(c, err...))
  651. }
  652. // AbortStatusExternalError abort with status code and log common.Error_EXTERNAL_ERROR to newrelic
  653. func AbortStatusExternalError(c *gin.Context, err ...error) {
  654. AbortExternalError(c, 500, err...)
  655. }