| 3 | const REAL_STATUS = Symbol('response realStatus'); |
| 4 | |
| 5 | export default class Response extends KoaResponse { |
| 6 | /** |
| 7 | * Get or set a real status code. |
| 8 | * |
| 9 | * e.g.: Using 302 status redirect to the global error page |
| 10 | * instead of show current 500 status page. |
| 11 | * And access log should save 500 not 302, |
| 12 | * then the `realStatus` can help us find out the real status code. |
| 13 | * @member {Number} Response#realStatus |
| 14 | * @return {Number} The status code to be set. |
| 15 | */ |
| 16 | get realStatus(): number { |
| 17 | if (this[REAL_STATUS]) { |
| 18 | return this[REAL_STATUS] as number; |
| 19 | } |
| 20 | return this.status; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Set a real status code. |
| 25 | * |
| 26 | * e.g.: Using 302 status redirect to the global error page |
| 27 | * instead of show current 500 status page. |
| 28 | * And access log should save 500 not 302, |
| 29 | * then the `realStatus` can help us find out the real status code. |
| 30 | * @member {Number} Response#realStatus |
| 31 | * @param {Number} status The status code to be set. |
| 32 | */ |
| 33 | set realStatus(status: number) { |
| 34 | this[REAL_STATUS] = status; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | declare module '@eggjs/core' { |
| 39 | // add Response overrides types |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…