@@ -9,6 +9,22 @@ axios.defaults.xsrfHeaderName = "X-CSRFToken"
99axios . defaults . xsrfCookieName = "csrftoken"
1010configureAxiosRequestId ( axios )
1111
12+ function translateApiMessage ( message ) {
13+ if ( typeof message !== "string" ) {
14+ return message
15+ }
16+ const normalized = message . trim ( ) . replace ( / \. $ / , "" )
17+ const messageMap = {
18+ "Problem does not exist" : "문제를 찾을 수 없습니다." ,
19+ "Problem doesn't exist" : "문제를 찾을 수 없습니다." ,
20+ "Problem does not exists" : "문제를 찾을 수 없습니다." ,
21+ "Problem not exist" : "문제를 찾을 수 없습니다." ,
22+ "Contest does not exist" : "대회를 찾을 수 없습니다." ,
23+ "Contest doesn't exist" : "대회를 찾을 수 없습니다." ,
24+ }
25+ return messageMap [ normalized ] || message
26+ }
27+
1228export default {
1329 getPopup ( ) {
1430 return ajax ( "popup" , "get" )
@@ -220,6 +236,7 @@ export default {
220236 params : {
221237 problem_id : problemID ,
222238 } ,
239+ silentError : true ,
223240 } )
224241 } ,
225242 getProblemLLMHintUrl ( problemID , userCode , contestID ) {
@@ -334,6 +351,7 @@ export default {
334351 contest_id : contestID ,
335352 problem_id : problemID ,
336353 } ,
354+ silentError : true ,
337355 } )
338356 } ,
339357 submitCode ( data ) {
@@ -492,9 +510,10 @@ export default {
492510 */
493511function ajax ( url , method , options ) {
494512 if ( options !== undefined ) {
495- var { params = { } , data = { } } = options
513+ var { params = { } , data = { } , silentError = false } = options
496514 } else {
497515 params = data = { }
516+ silentError = false
498517 }
499518 return new Promise ( ( resolve , reject ) => {
500519 axios ( {
@@ -506,10 +525,15 @@ function ajax(url, method, options) {
506525 ( res ) => {
507526 // API正常返回(status=20x), 是否错误通过有无error判断
508527 if ( res . data . error !== null ) {
509- Vue . prototype . $error ( res . data . data )
528+ if ( ! silentError ) {
529+ Vue . prototype . $error ( translateApiMessage ( res . data . data ) )
530+ }
510531 reject ( res )
511532 // 若后端返回为登录,则为session失效,应退出当前登录用户
512- if ( res . data . data . startsWith ( "Please login" ) ) {
533+ if (
534+ typeof res . data . data === "string" &&
535+ res . data . data . startsWith ( "Please login" )
536+ ) {
513537 store . dispatch ( "changeModalStatus" , {
514538 mode : "login" ,
515539 visible : true ,
@@ -527,7 +551,9 @@ function ajax(url, method, options) {
527551 const res = error . response || error
528552 const data = res . data || { }
529553 const message = data . data || error . message || "Server error"
530- Vue . prototype . $error ( message )
554+ if ( ! silentError ) {
555+ Vue . prototype . $error ( translateApiMessage ( message ) )
556+ }
531557 reject ( error )
532558 if ( typeof message === "string" && message . startsWith ( "Please login" ) ) {
533559 store . dispatch ( "changeModalStatus" , {
0 commit comments